diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-01-29 22:41:05 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-01-29 22:41:05 +0000 |
| commit | 4031b59b19152bb3e9e2d323caa7faffb7557c82 (patch) | |
| tree | 23bf32d4e45b810728dddda775b8ab71e1a08cbf /spec | |
| parent | initial commit (diff) | |
| download | alive-4031b59b19152bb3e9e2d323caa7faffb7557c82.tar.gz alive-4031b59b19152bb3e9e2d323caa7faffb7557c82.zip | |
support tagging
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/ast_spec.moon | 15 | ||||
| -rw-r--r-- | spec/parsing_spec.moon (renamed from spec/peg_spec.moon) | 65 |
2 files changed, 62 insertions, 18 deletions
diff --git a/spec/ast_spec.moon b/spec/ast_spec.moon new file mode 100644 index 0000000..402ce03 --- /dev/null +++ b/spec/ast_spec.moon @@ -0,0 +1,15 @@ +import Atom, Xpr from require 'ast' + +describe 'Xpr', -> + it 'can be walked', -> + aa = Xpr { '', (Atom '1', '', 1), '' } + ab = Xpr { '', (Atom '2', '', 2), '' } + ac = Xpr { '', (Atom '3', '', 3), '' } + b = Xpr { '', aa, ' ', ab, '' } + + root = Xpr { '', ac, ' ', b, '' }, 'naked' + + iter = root\walk_sexpr! + for res in *{ ac, b, aa, ab } + assert.is.equal res, iter! + assert.is.nil iter! diff --git a/spec/peg_spec.moon b/spec/parsing_spec.moon index 1b25406..5e6e1fc 100644 --- a/spec/peg_spec.moon +++ b/spec/parsing_spec.moon @@ -51,21 +51,50 @@ describe 'nexpr parsing', -> assert.is.equal ' 3\tok-yes\n', node\stringify! -test 'sexpr parsing', -> - str = '( 3 ok-yes - "friend" )' - node = sexpr\match str - - assert.is.equal '(', node.style - assert.is.equal 3, #node - assert.is.equal 3, node[1].value - assert.is.equal 'ok-yes', node[2].value - assert.is.equal 'friend', node[3].value - - assert.is.equal str, node\stringify! - -test 'mixed parsing', -> - str = '( 3 ok-yes - "friend" )' - node = program\match str - assert.is.equal str, node\stringify! +describe 'sexpr', -> + test 'basic parsing', -> + str = '( 3 ok-yes + "friend" )' + node = sexpr\match str + + assert.is.equal '(', node.style + assert.is.equal 3, #node + assert.is.equal 3, node[1].value + assert.is.equal 'ok-yes', node[2].value + assert.is.equal 'friend', node[3].value + + assert.is.equal str, node\stringify! + + test 'tag parsing', -> + str = '([42]tagged 2)' + node = sexpr\match str + + assert.is.equal '(', node.style + assert.is.equal 2, #node + assert.is.equal 'tagged', node[1].value + assert.is.equal 2, node[2].value + + assert.is.equal 42, node.tag + assert.is.equal str, node\stringify! + +describe 'resynthesis', -> + test 'mixed parsing', -> + str = '( 3 ok-yes + "friend" )' + node = program\match str + assert.is.equal str, node\stringify! + + test 'complex', -> + str = ' + (osc "/radius" (lfo (cc 14))) + + (osc rot + (step + (note "kick") + (random-rot) + (random-rot) + (random-rot) + (random-rot) + ) + ) ' + assert.is.equal str, (program\match str)\stringify! |
