Permalink
Browse files

om.rhythm: detailed tests of parsing/unparsing

  • Loading branch information...
1 parent 98b4350 commit 5a15c8dd90f252547ed705cf67c8fd8f9475974a @k7f committed Apr 10, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 work/om/rhythm/rhythm-tests.factor
@@ -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

0 comments on commit 5a15c8d

Please sign in to comment.