2019-05-11 13:01:39 -05:00
|
|
|
defmodule LytlangTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
doctest Lytlang
|
|
|
|
|
2019-11-15 00:51:27 -06:00
|
|
|
test "arithmetic" do
|
|
|
|
[
|
2019-11-19 22:24:17 -06:00
|
|
|
{"2", 2},
|
|
|
|
{"1 + 2", 3},
|
2019-11-15 00:51:27 -06:00
|
|
|
{"2 + 3 + 8", 13},
|
2019-11-19 22:24:17 -06:00
|
|
|
{"(2 + 3) * 8", 40},
|
2019-11-15 00:51:27 -06:00
|
|
|
{"2 * 3 + 8", 14},
|
|
|
|
{"2 + 3 * 8", 26},
|
|
|
|
{"2 * (3 + 8)", 22},
|
|
|
|
{"2 + (3 * 8)", 26},
|
|
|
|
{"8 - 3", 5},
|
|
|
|
{"8 / 4", 2.0},
|
2019-11-19 22:24:17 -06:00
|
|
|
{"8 // 4", 2},
|
2019-11-15 11:19:38 -06:00
|
|
|
{"a = 8\na + 9", 17},
|
2019-11-15 00:51:27 -06:00
|
|
|
{"2 + 3", 5}
|
|
|
|
]
|
|
|
|
|> Enum.map(fn {string, val} ->
|
|
|
|
assert Lytlang.eval(string) == val
|
|
|
|
end)
|
2019-05-11 13:01:39 -05:00
|
|
|
end
|
|
|
|
end
|