Skip to content

Commit

Permalink
Test evaluation of expresssion with missing variable and missing obje…
Browse files Browse the repository at this point in the history
…ct key
  • Loading branch information
dylanahsmith committed Oct 7, 2020
1 parent d6547af commit 2855e4a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/unit/expression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ def test_find_dynamic_variable
assert_equal 42, context.evaluate(expr)
end

def test_find_missing_variable
context = Liquid::Context.new({})
expr = Liquid::C::Expression.strict_parse('missing')

assert_nil context.evaluate(expr)

context.strict_variables = true

assert_raises(Liquid::UndefinedVariable) do
context.evaluate(expr)
end
end

def test_lookup_const_key
context = Liquid::Context.new({"obj" => { "prop" => "some value" }})

Expand All @@ -70,6 +83,19 @@ def test_lookup_command
assert_equal 'c', context.evaluate(Liquid::C::Expression.strict_parse('ary.last'))
end

def test_lookup_missing_key
context = Liquid::Context.new({ 'obj' => {} })
expr = Liquid::C::Expression.strict_parse('obj.missing')

assert_nil context.evaluate(expr)

context.strict_variables = true

assert_raises(Liquid::UndefinedVariable) do
context.evaluate(expr)
end
end

def test_const_range
assert_equal (1..2), Liquid::C::Expression.strict_parse('(1..2)')
end
Expand Down

0 comments on commit 2855e4a

Please sign in to comment.