ref: 97bb39c4c2790ea6aa62bbf2779f879fcd9273cf
parent: cd9755da503c8e8713171c59f840f1b08820495a
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jun 18 08:20:17 EDT 2015
Update to new APIs/mbld.
--- a/lib/date/bld.proj
+++ b/lib/date/bld.proj
@@ -6,3 +6,5 @@
types.myr
zoneinfo.myr
;;
+
+sub = test ;;
--- a/lib/date/fmt.myr
+++ b/lib/date/fmt.myr
@@ -5,7 +5,7 @@
pkg date =
const Datetimefmt = "%Y-%m-%d %H:%M:%S %z"
- const Timefmt = "%h:%m:%s %z"
+ const Timefmt = "%h:%m:{} %z"
const Datefmt = "%Y-%m-%d %z"
const fmt : (f : byte[:], d : instant -> byte[:])
@@ -31,54 +31,54 @@
if c == '%'
(c, f) = std.striter(f)
match c
- | 'a': s = std.bfmt(buf[o:], "%s", _names.abbrevday[d.day])
- | 'A': s = std.bfmt(buf[o:], "%s", _names.fullday[d.day])
- | 'b': s = std.bfmt(buf[o:], "%s", _names.abbrevmon[d.mon])
- | 'B': s = std.bfmt(buf[o:], "%s", _names.fullmon[d.mon])
+ | 'a': s = std.bfmt(buf[o:], "{}", _names.abbrevday[d.day])
+ | 'A': s = std.bfmt(buf[o:], "{}", _names.fullday[d.day])
+ | 'b': s = std.bfmt(buf[o:], "{}", _names.abbrevmon[d.mon])
+ | 'B': s = std.bfmt(buf[o:], "{}", _names.fullmon[d.mon])
| 'c': s = bfmt(buf[o:], "%Y-%m-%d", d)
- | 'C': s = std.bfmt(buf[o:], "%02i", d.year % 100)
- | 'd': s = std.bfmt(buf[o:], "%02i", d.day)
- | 'D': s = std.bfmt(buf[o:], "%m/%d/%y (wtf america)", d.mon, d.day, d.year)
- | 'e': s = std.bfmt(buf[o:], "%2i", d.day)
- | 'F': s = std.bfmt(buf[o:], "%y-%m-%d", d.year, d.mon, d.day)
+ | 'C': s = std.bfmt(buf[o:], "{02}", d.year % 100)
+ | 'd': s = std.bfmt(buf[o:], "{02}", d.day)
+ | 'D': s = bfmt(buf[o:], "%m/%d/%y (wtf america)", d)
+ | 'e': s = std.bfmt(buf[o:], "{2}", d.day)
+ | 'F': s = bfmt(buf[o:], "%y-%m-%d", d)
/*
| 'G': s = std.bfmt(buf[o:], ...?
| 'g':
*/
- | 'h': s = std.bfmt(buf[o:], "%s", _names.abbrevmon[d.mon])
- | 'H': s = std.bfmt(buf[o:], "%02i", d.h)
- | 'I': s = std.bfmt(buf[o:], "%02i", d.h % 12)
+ | 'h': s = std.bfmt(buf[o:], "{}", _names.abbrevmon[d.mon])
+ | 'H': s = std.bfmt(buf[o:], "{02}", d.h)
+ | 'I': s = std.bfmt(buf[o:], "{02}", d.h % 12)
| 'j': s = std.bfmt(buf[o:], "year day... unimplemented.")
- | 'k': s = std.bfmt(buf[o:], "%i", d.h)
- | 'l': s = std.bfmt(buf[o:], "%i", d.h % 12)
- | 'm': s = std.bfmt(buf[o:], "%i", d.mon)
- | 'M': s = std.bfmt(buf[o:], "%i", d.m)
+ | 'k': s = std.bfmt(buf[o:], "{}", d.h)
+ | 'l': s = std.bfmt(buf[o:], "{}", d.h % 12)
+ | 'm': s = std.bfmt(buf[o:], "{}", d.mon)
+ | 'M': s = std.bfmt(buf[o:], "{}", d.m)
| 'n': s = std.bfmt(buf[o:], "\n")
| 'O': s = std.bfmt(buf[o:], "unsupported %O")
- | 'p': s = std.bfmt(buf[o:], "%s", ["AM", "PM"][d.h/12])
- | 'P': s = std.bfmt(buf[o:], "%s", ["am", "pm"][d.h/12])
+ | 'p': s = std.bfmt(buf[o:], "{}", ["AM", "PM"][d.h/12])
+ | 'P': s = std.bfmt(buf[o:], "{}", ["am", "pm"][d.h/12])
| 'r': s = bfmt(buf[o:], "%H:%M:%S %P", d)
| 'R': s = bfmt(buf[o:], "%H:%M %P", d)
- | 's': s = std.bfmt(buf[o:], "%l", d.actual)
- | 'S': s = std.bfmt(buf[o:], "%i", d.s)
+ | 's': s = std.bfmt(buf[o:], "{}", d.actual)
+ | 'S': s = std.bfmt(buf[o:], "{}", d.s)
| 't': s = std.bfmt(buf[o:], "\t")
- | 'u': s = std.bfmt(buf[o:], "%i", d.wday)
+ | 'u': s = std.bfmt(buf[o:], "{}", d.wday)
| 'U': s = std.bfmt(buf[o:], "week number... unimplemented.")
| 'x': s = bfmt(buf[o:], Datefmt, d)
| 'X': s = bfmt(buf[o:], Timefmt, d)
- | 'y': s = std.bfmt(buf[o:], "%i", d.year % 100)
- | 'Y': s = std.bfmt(buf[o:], "%i", d.year)
+ | 'y': s = std.bfmt(buf[o:], "{}", d.year % 100)
+ | 'Y': s = std.bfmt(buf[o:], "{}", d.year)
| 'z': s = timezone(buf[o:], d.tzoff)
- | 'Z': s = std.bfmt(buf[o:], "%s", d.tzname)
- | '%': s = std.bfmt(buf[o:], "%%")
- | _: std.fatal("unknown format character %c\n", c)
+ | 'Z': s = std.bfmt(buf[o:], "{}", d.tzname)
+ | '%': s = std.bfmt(buf[o:], "%")
+ | _: std.fatal("unknown format character {}\n", c)
;;
else
- s = std.bfmt(buf[o:], "%c", c)
+ s = std.bfmt(buf[o:], "{}", c)
;;
o += s.len
;;
- -> s
+ -> buf[:o]
}
const timezone = {buf, off
@@ -93,5 +93,5 @@
off /= 1_000_000
h = off / 3600
m = off % 3600
- -> std.bfmt(buf, "%s%02l%02l", sep, h, m)
+ -> std.bfmt(buf, "{}{02}{02}", sep, h, m)
}
--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -173,6 +173,7 @@
;;
s = intval(&tzoff, s[1:], 2, 4, err)
dst# = (tzoff / 100) * 3600 * 1_000_000 + (tzoff % 100) * 60 * 1_000_000
+ -> s
}
--- a/lib/date/test/Makefile
+++ /dev/null
@@ -1,20 +1,0 @@
-# don't build anything for 'all'
-all:
- $(MAKE) -C ..
-
-check:
- ./runtest.sh
-
-.PHONY: %
-%:
- ./runtest.sh $@
-
-.PHONY: clean
-clean:
- rm -f testmatch.use testmatch.o
- @for i in `awk '/^[A-Z]/{print $$2}' tests`; do \
- echo rm -f $$i; \
- rm -f $$i; \
- done
-
-install:
--- /dev/null
+++ b/lib/date/test/bld.sub
@@ -1,0 +1,2 @@
+test ftime-test {inc=..} = ftime-test.myr ;;
+test parse-test {inc=..} = parse-test.myr ;;
--- a/lib/date/test/data/ftime-test-expected
+++ /dev/null
@@ -1,1 +1,0 @@
-2014-8-29 19:47:43 +0000
--- a/lib/date/test/data/parse-test-expected
+++ /dev/null
@@ -1,1 +1,0 @@
-1932-10-23 00:0:0 +0500
--- a/lib/date/test/ftime-test.myr
+++ b/lib/date/test/ftime-test.myr
@@ -4,10 +4,16 @@
const main = {
var buf : byte[1024]
var d
- var n
+ var f
/*Fri 29 Aug 2014 07:47:43 PM UTC*/
- d = date.mkdate(1_409_341_663*1_000_000, "")
- n = date.bfmt(buf[:], date.Datetimefmt, d)
- std.put("%s\n", buf[:n])
+ d = date.mkinstant(1_409_341_663*1_000_000, "")
+ f = date.bfmt(buf[:], date.Datetimefmt, d)
+ eq("2014-8-29 19:47:43 +0000", f)
+}
+
+const eq = {expected, actual
+ if !std.sleq(expected, actual)
+ std.fatal("expected date {}, got {}\n", expected, actual)
+ ;;
}
--- a/lib/date/test/parse-test.myr
+++ b/lib/date/test/parse-test.myr
@@ -3,12 +3,18 @@
const main = {
var buf : byte[1024]
- var n
/*Fri 29 Aug 2014 07:47:43 PM UTC*/
match date.parsefmt("%Y-%m-%d %z", "1932-10-23 +0500")
| `std.Some d:
- n = date.bfmt(buf[:], date.Datetimefmt, d)
- std.put("%s\n", buf[:n])
+ eq(date.bfmt(buf[:], date.Datetimefmt, d), "1932-10-23 00:0:0 +0500")
+ | `std.None:
+ std.fatal("Failed to parse date")
+ ;;
+}
+
+const eq = {expected, actual
+ if !std.sleq(expected, actual)
+ std.fatal("expected date {}, got {}\n", expected, actual)
;;
}
--- a/lib/date/test/runtest.sh
+++ /dev/null
@@ -1,124 +1,0 @@
-#!/bin/bash
-NFAILURES=0
-NPASSES=0
-
-function build {
- rm -f $1 $1.o $1.s $1.use
- myrbuild $FLAGS -b $1 $1.myr $EXTRA_SRC
-}
-
-function pass {
- PASSED="$PASSED $1"
- NPASSED=$[$NPASSED + 1]
-}
-
-function fail {
- echo "FAIL: $1"
- FAILED="$FAILED $1"
- NFAILED=$[$NFAILED + 1]
-}
-
-function expectstatus {
- ./$1 $3
- if [ $? -eq $2 ]; then
- pass $1
- return
- else
- fail $1
- fi
-}
-
-function expectprint {
- if [ "`./$1 $3`" != "$2" ]; then
- fail $1
- else
- pass $1
- fi
-}
-
-
-function expectcompare {
- if [ x"" != x"$TMPDIR" ]; then
- t=$TMPDIR/myrtest-$1-$RANDOM
- else
- t=/tmp/myrtest-$1-$RANDOM
- fi
- ./$1 $3 > $t
- if cmp $t data/$1-expected; then
- pass $1
- else
- fail $1
- fi
- rm -f $t
-}
-
-function expectfcompare {
- ./$1 $3
- if cmp data/$1-expected $2; then
- pass $1
- else
- fail $1
- fi
-}
-
-function shouldskip {
- if [ -z $ARGS ]; then
- return 1
- fi
-
- for i in $ARGS; do
- if [ $i = $1 ]; then
- return 1
- fi
- done
- return 0
-}
-
-
-# Should build and run
-function B {
- if shouldskip $1; then
- return
- fi
-
- test="$1"; shift
- type="$1"; shift
- res="$1"; shift
- if [ $# > 0 ]; then
- args="$1"; shift
- fi
- build $test
- case $type in
- "E") expectstatus "$test" "$res" "$input";;
- "P") expectprint "$test" "$res" "$input";;
- "C") expectcompare "$test" "$res" "$input";;
- "F") expectfcompare "$test" "$res" "$args";;
- esac
-}
-
-# Should fail
-function F {
- if shouldskip $1; then
- return
- fi
- (build $1) > /dev/null
- if [ $? -eq '1' ]; then
- pass $1
- else
- fail $1
- fi
-}
-
-# Should generate a usefile
-function U {
- return
-}
-
-source tests
-
-echo "PASSED ($NPASSED): $PASSED"
-if [ -z "$NFAILED" ]; then
- echo "SUCCESS"
-else
- echo "FAILURES ($NFAILED): $FAILED"
-fi
--- a/lib/date/test/tests
+++ /dev/null
@@ -1,24 +1,0 @@
-FLAGS=-I../
-mkdir -p tmpout
-# Format:
-# [B|F] testname [E|P] result
-# [B|F]: Compiler outcome.
-# B: Expect that this test will build.
-# F: Expect that this test will not build.
-# testname: Test case
-# The test that will run. We will try to
-# compile 'testname.myr' to 'testname',
-# and then execute it, verifying the result
-# [E|P|C]: Result type
-# E tells us that the result is an exit status
-# P tells us that the result is on stdout,
-# and should be compared to the value on the
-# line
-# C tells us that the result is on stdout,
-# and should be compared to the contents of
-# the file passed on the line.
-# result: Result value
-# What we compare with. This should be self-
-# evident.
-B ftime-test C
-B parse-test C