Class: TestQuiz

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/sql/bathon-sxp.rb

Instance Method Summary collapse

Instance Method Details

#test_ihavenocluewhyObject



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_indexoperatorObject



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_orObject



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_methodcallObject



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_selfObject



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_1Object



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_2Object



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_3Object



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_callObject



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_symsObject



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_evalObject



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_argsObject



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_emptyObject



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_comObject



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_litsObject



179
180
181
# File 'lib/sql/bathon-sxp.rb', line 179

def test_sxp_lits
  assert_equal 8, sxp{8}
end

#test_sxp_nested_callsObject



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_notObject



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_nilObject



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_variablesObject



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

#test_sxp_vcallObject



151
152
153
# File 'lib/sql/bathon-sxp.rb', line 151

def test_sxp_vcall
  assert_equal [:abc], sxp{abc}
end