Class: TestQuiz
- Defined in:
- lib/sql/bathon-sxp.rb
Instance Method Summary collapse
- #test_ihavenocluewhy ⇒ Object
- #test_indexoperator ⇒ Object
- #test_keywords_and_or ⇒ Object
- #test_methodcall ⇒ Object
- #test_self ⇒ Object
- #test_sxp_binarymsg_mixed_1 ⇒ Object
- #test_sxp_binarymsg_mixed_2 ⇒ Object
- #test_sxp_binarymsg_mixed_3 ⇒ Object
- #test_sxp_binarymsg_mixed_call ⇒ Object
- #test_sxp_binarymsg_syms ⇒ Object
- #test_sxp_call_plus_eval ⇒ Object
- #test_sxp_call_with_multiple_args ⇒ Object
- #test_sxp_empty ⇒ Object
- #test_sxp_from_sander_dot_land_at_gmail_com ⇒ Object
- #test_sxp_lits ⇒ Object
- #test_sxp_nested_calls ⇒ Object
- #test_sxp_not ⇒ Object
- #test_sxp_true_false_nil ⇒ Object
- #test_sxp_variables ⇒ Object
- #test_sxp_vcall ⇒ Object
Instance Method Details
#test_ihavenocluewhy ⇒ Object
228 229 230 231 232 233 |
# File 'lib/sql/bathon-sxp.rb', line 228 def test_ihavenocluewhy assert_equal 11, 5 + 6 assert_raise(TypeError) { 7 / :field } assert_raise(NoMethodError) { 7+count(:field) } assert_raise(NoMethodError) { :field > 5 } end |
#test_indexoperator ⇒ Object
246 247 248 249 |
# File 'lib/sql/bathon-sxp.rb', line 246 def test_indexoperator Symbol.class_eval { define_method :[] do |arg| self end } assert_equal :table, sxp{:table[:field]} end |
#test_keywords_and_or ⇒ Object
251 252 253 254 255 256 |
# File 'lib/sql/bathon-sxp.rb', line 251 def test_keywords_and_or assert_equal [:|, [:<, 1, 2], [:<, 3, 4]], sxp{1<2 or 3<4} assert_equal [:|, [:<, 1, 2], [:<, 3, 4]], sxp{1<2 || 3<4} assert_equal [:&, [:<, 1, 2], [:<, 3, 4]], sxp{1<2 and 3<4} assert_equal [:&, [:<, 1, 2], [:<, 3, 4]], sxp{1<2 && 3<4} end |
#test_methodcall ⇒ Object
235 236 237 238 239 240 241 242 243 244 |
# File 'lib/sql/bathon-sxp.rb', line 235 def test_methodcall #free functions should be turned in to s-expressions #binary operators (which are specially-named methods) should be # turned into s-expressions #(these are tested in other tests) #but bound functions should be called, and this is what's tested #here assert_equal [:+,3,5], sxp{ 3 + "hello".length } end |
#test_self ⇒ Object
258 259 260 261 262 |
# File 'lib/sql/bathon-sxp.rb', line 258 def test_self assert_equal self, sxp{self} assert_equal [:object_id], sxp{object_id} assert_equal object_id, sxp{self.object_id} end |
#test_sxp_binarymsg_mixed_1 ⇒ Object
163 164 165 |
# File 'lib/sql/bathon-sxp.rb', line 163 def test_sxp_binarymsg_mixed_1 assert_equal [:+, 3, :symbol], sxp{3+:symbol} end |
#test_sxp_binarymsg_mixed_2 ⇒ Object
171 172 173 |
# File 'lib/sql/bathon-sxp.rb', line 171 def test_sxp_binarymsg_mixed_2 assert_equal [:/, 7, :field], sxp{7/:field} end |
#test_sxp_binarymsg_mixed_3 ⇒ Object
175 176 177 |
# File 'lib/sql/bathon-sxp.rb', line 175 def test_sxp_binarymsg_mixed_3 assert_equal [:>, :field, 5], sxp{:field > 5} end |
#test_sxp_binarymsg_mixed_call ⇒ Object
167 168 169 |
# File 'lib/sql/bathon-sxp.rb', line 167 def test_sxp_binarymsg_mixed_call assert_equal [:+, 3, [:count, :field]], sxp{3+count(:field)} end |
#test_sxp_binarymsg_syms ⇒ Object
192 193 194 |
# File 'lib/sql/bathon-sxp.rb', line 192 def test_sxp_binarymsg_syms assert_equal [:==, :field1, :field2], sxp{:field1 == :field2 } end |
#test_sxp_call_plus_eval ⇒ Object
155 156 157 |
# File 'lib/sql/bathon-sxp.rb', line 155 def test_sxp_call_plus_eval assert_equal [:count, [:+, 3, 7]], sxp{count(3+7)} end |
#test_sxp_call_with_multiple_args ⇒ Object
159 160 161 |
# File 'lib/sql/bathon-sxp.rb', line 159 def test_sxp_call_with_multiple_args assert_equal [:count, 3, 7], sxp{count(3,7)} end |
#test_sxp_empty ⇒ Object
188 189 190 |
# File 'lib/sql/bathon-sxp.rb', line 188 def test_sxp_empty assert_equal nil, sxp{} end |
#test_sxp_from_sander_dot_land_at_gmail_com ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sql/bathon-sxp.rb', line 210 def test_sxp_from_sander_dot_land_at_gmail_com assert_equal [:==,[:^, 2, 3], [:^, 1, 1]], sxp{ 2^3 == 1^1} assert_equal [:==, [:+, 3.0, 0.1415], 3], sxp{3.0 + 0.1415 == 3} assert_equal([:|, [:==, [:+, :hello, :world], :helloworld], [:==, [:+, [:+, "hello", " "], "world"], "hello world"]] , sxp { (:hello + :world == :helloworld) | ('hello' + ' ' + 'world' == 'hello world') }) # assert_equal [:==, [:+, [:abs, [:factorial, 3]], # [:*, [:factorial, 4], 42]], # [:+, [:+, 4000000, [:**, 2, 32]], [:%, 2.7, 1.1]]], # sxp{ 3.factorial.abs + 4.factorial * 42 == 4_000_000 + 2**32 + 2.7 % 1.1 } end |
#test_sxp_lits ⇒ Object
179 180 181 |
# File 'lib/sql/bathon-sxp.rb', line 179 def test_sxp_lits assert_equal 8, sxp{8} end |
#test_sxp_nested_calls ⇒ Object
147 148 149 |
# File 'lib/sql/bathon-sxp.rb', line 147 def test_sxp_nested_calls assert_equal [:max, [:count, :name]], sxp{max(count(:name))} end |
#test_sxp_not ⇒ Object
205 206 207 208 |
# File 'lib/sql/bathon-sxp.rb', line 205 def test_sxp_not assert_equal [:not, :field], sxp{ not :field } assert_equal [:"!=", :a, :b], sxp{ :a != :b } end |
#test_sxp_true_false_nil ⇒ Object
183 184 185 186 |
# File 'lib/sql/bathon-sxp.rb', line 183 def test_sxp_true_false_nil assert_equal [:+, true, false], sxp{true+false} assert_equal nil, sxp{nil} end |
#test_sxp_variables ⇒ Object
196 197 198 199 200 201 202 203 |
# File 'lib/sql/bathon-sxp.rb', line 196 def test_sxp_variables lvar = :field # local variable assert_equal [:count, :field], sxp{ count(lvar) } proc { dvar = :field2 # dynavar (block local variable) assert_equal [:==, :field, :field2], sxp{ lvar == dvar } }.call end |