File tree Expand file tree Collapse file tree 2 files changed +19
-18
lines changed
Expand file tree Collapse file tree 2 files changed +19
-18
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,11 @@ class PreParseError < StandardError ; end
2323 def self . preparse ( rb )
2424 SonicPi ::SpiderAPI . ring_fns . each do |fn |
2525 fn = fn [ :name ] . to_s
26- rb . gsub! ( /\( (\s *)#{ fn } (\s )/ , '\1' + ' ' + fn + '(\2' )
27- raise PreParseError , "You may not use the built-in fn names as variable names.\n You attempted to use: #{ fn } " if rb . match ( /\W #{ fn } \s *=[\s \w ]/ )
26+ rb . gsub! ( /\( (\s *)#{ fn } (\s )/ , '\1' + fn + '(\2' )
27+
28+ if rb . match ( /(?!\B )\W ?#{ fn } \s *=[\s \w ]/ )
29+ raise PreParseError , "You may not use the built-in fn names as variable names.\n You attempted to use: #{ fn } "
30+ end
2831 end
2932 rb
3033 end
Original file line number Diff line number Diff line change 1515require_relative "../../core"
1616require_relative "../lib/sonicpi/preparser"
1717
18- module SonicPi
19- module PreParser
20-
21- class PreParseError < StandardError ; end
22-
23- def self . preparse ( rb )
24- SonicPi ::SpiderAPI . ring_fns . each do |fn |
25- fn = fn [ :name ] . to_s
26- rb . gsub! ( /\( (\s *)#{ fn } (\s )/ , '\1' + fn + '(\2' )
27- raise PreParseError , "You may not use the built-in fn names as variable names.\n You attempted to use: #{ fn } " if rb . match ( /\W ?#{ fn } \s *=[\s \w ]/ )
28- end
29- rb
30- end
31- end
32- end
33-
3418module SonicPi
3519 class PreParserTester < Test ::Unit ::TestCase
3620 def test_no_change
@@ -50,5 +34,19 @@ def test_raises_on_assignment_to_ring_fn
5034 PreParser . preparse ( a )
5135 end
5236 end
37+
38+ def test_partial_matches_on_builtin_fns
39+ a = "testscale = 10"
40+ assert_nothing_thrown PreParser ::PreParseError do
41+ PreParser . preparse ( a )
42+ end
43+ end
44+
45+ def test_using_a_builtin_raises_an_exception
46+ a = "scale = 10"
47+ assert_raise PreParser ::PreParseError do
48+ PreParser . preparse ( a )
49+ end
50+ end
5351 end
5452end
You can’t perform that action at this time.
0 commit comments