1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#--
# This file is part of Sonic Pi: http://sonic-pi.net
# Full project source: https://github.com/samaaron/sonic-pi
# License: https://github.com/samaaron/sonic-pi/blob/master/LICENSE.md
#
# Copyright 2013, 2014, 2015, 2016 by Sam Aaron (http://sam.aaron.name).
# All rights reserved.
#
# Permission is granted for use, copying, modification, and
# distribution of modified versions of this work as long as this
# notice is included.
#++
require_relative "./setup_test"
require_relative "../lib/sonicpi/preparser"
module SonicPi
class PreParserTester < Minitest::Test
def test_no_change
a = " def test_resolution_of_basic_major\n assert_equal(Chord.new(:C4, :major), [60, 64, 67])\n assert_equal(Chord.new(60, :major), [60, 64, 67])\n end\n end\n\n end\nend"
assert_equal(a, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_basic_ring_change_w_frozen_string
a = "(ring 50, 60, 70)".freeze
b = " ring(50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_basic_ring_change
a = "(ring 50, 60, 70)"
b = " ring(50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_basic_ring_change_with_leading_space
a = "( ring 50, 60, 70)"
b = " ring(50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_basic_rings_with_commas
a = "(ring, 50, 60, 70)"
b = " ring( 50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_basic_rings_with_commas_and_no_space
a = "(ring,50, 60, 70)"
b = " ring(50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_spaced_rings_with_commas
a = "(ring , 50, 60, 70)"
b = " ring( 50, 60, 70)"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_raises_on_assignment_to_ring_fn
a = "ring = [50, 60, 70]"
assert_raises PreParser::PreParseError do
PreParser.preparse(a, SonicPi::Lang::Core.vec_fns)
end
end
def test_partial_matches_on_builtin_fns
a = "testscale = 10"
# minitest doesn't have a refute_raises
assert_equal(a, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_using_a_builtin_raises_an_exception
a = "scale = 10"
assert_raises PreParser::PreParseError do
PreParser.preparse(a, SonicPi::Lang::Core.vec_fns)
end
end
def test_sp_sym_basic_expansion
a = "foo :baz:quux eggs"
b = "foo ::SonicPi::SPSym.new('baz : quux') eggs"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_sp_sym_multiterm_expansion
a = "foo :baz:quux:bar:beans eggs"
b = "foo ::SonicPi::SPSym.new('baz : quux : bar : beans') eggs"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
def test_sp_sym_complex_expansion
a = "foo :baz?:quux eggs"
b = "foo ::SonicPi::SPSym.new('baz? : quux') eggs"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
a = "foo :baz?:qu_ux eggs"
b = "foo ::SonicPi::SPSym.new('baz? : qu_ux') eggs"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
a = "foo :_b_az?:qu_ux eggs :beans"
b = "foo ::SonicPi::SPSym.new('_b_az? : qu_ux') eggs :beans"
assert_equal(b, PreParser.preparse(a, SonicPi::Lang::Core.vec_fns))
end
end
end
|