io.crlf: add some unit tests; read-crlf now returns f on EOF
parent
e9e15ffb27
commit
86e97b0d9c
|
@ -0,0 +1,8 @@
|
||||||
|
IN: io.crlf.tests
|
||||||
|
USING: io.crlf tools.test io.streams.string io ;
|
||||||
|
|
||||||
|
[ "Hello, world." ] [ "Hello, world." [ read-crlf ] with-string-reader ] unit-test
|
||||||
|
[ "Hello, world." ] [ "Hello, world.\r\n" [ read-crlf ] with-string-reader ] unit-test
|
||||||
|
[ "Hello, world.\r" [ read-crlf ] with-string-reader ] must-fail
|
||||||
|
[ f ] [ "" [ read-crlf ] with-string-reader ] unit-test
|
||||||
|
[ "" ] [ "\r\n" [ read-crlf ] with-string-reader ] unit-test
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2009 Daniel Ehrenberg, Slava Pestov
|
! Copyright (C) 2009 Daniel Ehrenberg, Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: io kernel ;
|
USING: io kernel sequences ;
|
||||||
IN: io.crlf
|
IN: io.crlf
|
||||||
|
|
||||||
: crlf ( -- )
|
: crlf ( -- )
|
||||||
|
@ -8,4 +8,4 @@ IN: io.crlf
|
||||||
|
|
||||||
: read-crlf ( -- seq )
|
: read-crlf ( -- seq )
|
||||||
"\r" read-until
|
"\r" read-until
|
||||||
[ CHAR: \r assert= read1 CHAR: \n assert= ] when* ;
|
[ CHAR: \r assert= read1 CHAR: \n assert= ] [ f like ] if* ;
|
||||||
|
|
|
@ -1,21 +1,35 @@
|
||||||
! Copyright (C) 2007, 2008 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel vocabs vocabs.loader tools.time tools.vocabs
|
USING: kernel vocabs vocabs.loader tools.time tools.vocabs
|
||||||
arrays assocs io.styles io help.markup prettyprint sequences
|
arrays assocs io.styles io help.markup prettyprint sequences
|
||||||
continuations debugger math ;
|
continuations debugger math namespaces ;
|
||||||
IN: benchmark
|
IN: benchmark
|
||||||
|
|
||||||
: run-benchmark ( vocab -- result )
|
<PRIVATE
|
||||||
|
|
||||||
|
SYMBOL: timings
|
||||||
|
SYMBOL: errors
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: run-benchmark ( vocab -- )
|
||||||
[ "=== " write vocab-name print flush ] [
|
[ "=== " write vocab-name print flush ] [
|
||||||
[ [ require ] [ [ run ] benchmark ] bi ] curry
|
[ [ require ] [ [ run ] benchmark ] [ ] tri timings ]
|
||||||
[ error. f ] recover
|
[ swap errors ]
|
||||||
|
recover get set-at
|
||||||
] bi ;
|
] bi ;
|
||||||
|
|
||||||
: run-benchmarks ( -- assoc )
|
: run-benchmarks ( -- timings errors )
|
||||||
|
[
|
||||||
|
V{ } clone timings set
|
||||||
|
V{ } clone errors set
|
||||||
"benchmark" all-child-vocabs-seq
|
"benchmark" all-child-vocabs-seq
|
||||||
[ dup run-benchmark ] { } map>assoc ;
|
[ run-benchmark ] each
|
||||||
|
timings get
|
||||||
|
errors get
|
||||||
|
] with-scope ;
|
||||||
|
|
||||||
: benchmarks. ( assoc -- )
|
: timings. ( assocs -- )
|
||||||
standard-table-style [
|
standard-table-style [
|
||||||
[
|
[
|
||||||
[ "Benchmark" write ] with-cell
|
[ "Benchmark" write ] with-cell
|
||||||
|
@ -24,13 +38,21 @@ IN: benchmark
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
[ [ 1array $vocab-link ] with-cell ]
|
[ [ 1array $vocab-link ] with-cell ]
|
||||||
[ [ 1000000 /f pprint-cell ] [ [ "failed" write ] with-cell ] if* ] bi*
|
[ 1000000 /f pprint-cell ]
|
||||||
|
bi*
|
||||||
] with-row
|
] with-row
|
||||||
] assoc-each
|
] assoc-each
|
||||||
] tabular-output nl ;
|
] tabular-output nl ;
|
||||||
|
|
||||||
|
: benchmark-errors. ( errors -- )
|
||||||
|
[
|
||||||
|
[ "=== " write vocab-name print ]
|
||||||
|
[ error. ]
|
||||||
|
bi*
|
||||||
|
] assoc-each ;
|
||||||
|
|
||||||
: benchmarks ( -- )
|
: benchmarks ( -- )
|
||||||
run-benchmarks benchmarks. ;
|
run-benchmarks [ timings. ] [ benchmark-errors. ] bi* ;
|
||||||
|
|
||||||
MAIN: benchmarks
|
MAIN: benchmarks
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue