diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-06-18 12:20:17 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-06-18 12:20:17 -0700 |
commit | 97bb39c4c2790ea6aa62bbf2779f879fcd9273cf (patch) | |
tree | bff724151c98cb0c69d0464cbf848d938afc9175 /lib/date | |
parent | cd9755da503c8e8713171c59f840f1b08820495a (diff) | |
download | mc-97bb39c4c2790ea6aa62bbf2779f879fcd9273cf.tar.gz |
Update to new APIs/mbld.
Diffstat (limited to 'lib/date')
-rw-r--r-- | lib/date/bld.proj | 2 | ||||
-rw-r--r-- | lib/date/fmt.myr | 60 | ||||
-rw-r--r-- | lib/date/parse.myr | 1 | ||||
-rw-r--r-- | lib/date/test/Makefile | 20 | ||||
-rw-r--r-- | lib/date/test/bld.sub | 2 | ||||
-rw-r--r-- | lib/date/test/data/ftime-test-expected | 1 | ||||
-rw-r--r-- | lib/date/test/data/parse-test-expected | 1 | ||||
-rw-r--r-- | lib/date/test/ftime-test.myr | 14 | ||||
-rw-r--r-- | lib/date/test/parse-test.myr | 12 | ||||
-rwxr-xr-x | lib/date/test/runtest.sh | 124 | ||||
-rw-r--r-- | lib/date/test/tests | 24 |
11 files changed, 54 insertions, 207 deletions
diff --git a/lib/date/bld.proj b/lib/date/bld.proj index 8c59015..6886c8c 100644 --- a/lib/date/bld.proj +++ b/lib/date/bld.proj @@ -6,3 +6,5 @@ lib date = types.myr zoneinfo.myr ;; + +sub = test ;; diff --git a/lib/date/fmt.myr b/lib/date/fmt.myr index 5450db8..463f110 100644 --- a/lib/date/fmt.myr +++ b/lib/date/fmt.myr @@ -5,7 +5,7 @@ use "names.use" 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 @@ const bfmt = {buf, f, d 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 @@ const timezone = {buf, off 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) } diff --git a/lib/date/parse.myr b/lib/date/parse.myr index e1b64c7..88aff73 100644 --- a/lib/date/parse.myr +++ b/lib/date/parse.myr @@ -173,6 +173,7 @@ const timezone = {dst, s, err ;; s = intval(&tzoff, s[1:], 2, 4, err) dst# = (tzoff / 100) * 3600 * 1_000_000 + (tzoff % 100) * 60 * 1_000_000 + -> s } diff --git a/lib/date/test/Makefile b/lib/date/test/Makefile deleted file mode 100644 index e559327..0000000 --- a/lib/date/test/Makefile +++ /dev/null @@ -1,20 +0,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: diff --git a/lib/date/test/bld.sub b/lib/date/test/bld.sub new file mode 100644 index 0000000..76de596 --- /dev/null +++ b/lib/date/test/bld.sub @@ -0,0 +1,2 @@ +test ftime-test {inc=..} = ftime-test.myr ;; +test parse-test {inc=..} = parse-test.myr ;; diff --git a/lib/date/test/data/ftime-test-expected b/lib/date/test/data/ftime-test-expected deleted file mode 100644 index c45fbe0..0000000 --- a/lib/date/test/data/ftime-test-expected +++ /dev/null @@ -1 +0,0 @@ -2014-8-29 19:47:43 +0000 diff --git a/lib/date/test/data/parse-test-expected b/lib/date/test/data/parse-test-expected deleted file mode 100644 index 99dd5bf..0000000 --- a/lib/date/test/data/parse-test-expected +++ /dev/null @@ -1 +0,0 @@ -1932-10-23 00:0:0 +0500 diff --git a/lib/date/test/ftime-test.myr b/lib/date/test/ftime-test.myr index 89792f1..f29ba9b 100644 --- a/lib/date/test/ftime-test.myr +++ b/lib/date/test/ftime-test.myr @@ -4,10 +4,16 @@ use date 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) + ;; } diff --git a/lib/date/test/parse-test.myr b/lib/date/test/parse-test.myr index adc6b0f..1f86924 100644 --- a/lib/date/test/parse-test.myr +++ b/lib/date/test/parse-test.myr @@ -3,12 +3,18 @@ use date 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) ;; } diff --git a/lib/date/test/runtest.sh b/lib/date/test/runtest.sh deleted file mode 100755 index 95f548f..0000000 --- a/lib/date/test/runtest.sh +++ /dev/null @@ -1,124 +0,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 diff --git a/lib/date/test/tests b/lib/date/test/tests deleted file mode 100644 index 13d4f63..0000000 --- a/lib/date/test/tests +++ /dev/null @@ -1,24 +0,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 |