Sha256: bfac5d2bdfe4ed2870066a77eca636a3c232364428953f1bc5610e96fa122aa5
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
require 'spec_helper' describe SimpleLogic do it "should evaluate single variable" do context = { hungry: true } expression = "hungry" in_luck = SimpleLogic.eval(expression, context) expect(in_luck).to eq true end it "should evaluate negated variable" do context = { hungry: true } expression = "!hungry" in_luck = SimpleLogic.eval(expression, context) expect(in_luck).to eq false end it "should evaluate logical and" do context = { hungry: true, fridge_empty: false} expression = "hungry && fridge_empty" in_luck = SimpleLogic.eval(expression, context) expect(in_luck).to eq false end it "should evaluate logical or" do context = { hungry: true, fridge_empty: false} expression = "hungry || fridge_empty" in_luck = SimpleLogic.eval(expression, context) expect(in_luck).to eq true end it "should evaluate chained logic statements" do context = { hungry: true, fridge_empty: true, restaurant_nearby: true} expression = "hungry && !fridge_empty || restaurant_nearby" in_luck = SimpleLogic.eval(expression, context) expect(in_luck).to eq true end it "should raise an exception on a syntax error" do expect { SimpleLogic.eval("> hungry", {}) }.to raise_error {|e| expect(e.offset).to eq 0 } end it "should raise an exception on a syntax error and indicate location of parse error" do expect { SimpleLogic.eval("testing > hungry", {testing: true}) }.to raise_error(SimpleLogic::ParseError) {|e| expect(e.offset).to eq 7 } end it "should raise an exception on undefined variable" do expect { SimpleLogic.eval("testing && hungry", {testing: true}) }.to raise_error(SimpleLogic::UndefinedVariableError) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_logic-0.0.1 | spec/simple_logic_spec.rb |