Skip to content

Commit

Permalink
om.rhythm: detailed tests of parsing/unparsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Czaja committed Apr 10, 2012
1 parent 98b4350 commit 5a15c8d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions work/om/rhythm/rhythm-tests.factor
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
! Copyright (C) 2012 krzYszcz.
! See http://factorcode.org/license.txt for BSD license.

USING: accessors arrays eval io.streams.string kernel macros math om.rhythm
prettyprint sequences tools.test ;
USING: accessors addenda.eval addenda.prettyprint arrays io.streams.string
kernel math om.rhythm prettyprint sequences tools.test ;
IN: om.rhythm.tests

: parse-unparse-literal ( token vocabs -- token' obj )
" " join "USING: " " ; " surround prepend
( -- obj ) eval
[ [ pprint ] with-string-writer ] keep ;
[
"T{ rhythm-tree { duration 1 } { division { T{ rhythm-tree { duration 1 } { division { -1 } } } } } }"
] [
{< {< >} >} unparse-tuple
] unit-test

: (reparse-literal) ( token vocabs -- obj token' )
eval-using [ [ pprint ] with-string-writer ] keep swap ; inline

: reparse-literal ( token vocabs -- obj ? )
over [ parse-unparse-literal swap ] dip = ;
over [ (reparse-literal) ] dip = ;

[
{ { {< >} t } { {< >} f } { {< >} f }
{ {< -2 >} t } { {< 1 >} t } { {< 2 >} t } { {< 3//4 >} t }
{ {< >} f } { {< 2 >< >} t } { {< 3//4 >} f }
{ {< >} f } { {< -2 >} f } { {< 1 >} f } { {< 2 >} f }
{ {< {< >} >} t }
}
] [
{ "{< >}" "{< >< >}" "{< -1 >}"
"{< -2 >}" "{< 1 >}" "{< 2 >}" "{< 3//4 >}"
"{< 1 >< >}" "{< 2 >< >}" "{< 3//4 >< >}"
"{< >< -1 >}" "{< >< -2 >}" "{< >< 1 >}" "{< >< 2 >}"
"{< {< >} >}"
}
[ { "om.rhythm" } reparse-literal 2array ] map
] unit-test
Expand Down

0 comments on commit 5a15c8d

Please sign in to comment.