Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some testcases #39

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion logics-py/logics/logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, src: str, debug: bool = False):
"round": lambda value, digits=0: round(float(value), int(digits)),
"rstrip": lambda value, chars=" \t\r\n": str(value).rstrip(str(chars)),
"split": lambda value, delimiter=" ": str(value).split(str(delimiter)),
"str": str,
"str": lambda val: Value(str(val), optimize=False),
"strip": lambda s, c=" \t\r\n": str(s).strip(str(c)),
"sum": lambda value: sum([Value.align(item, allow=(bool, int, float), default=0) for item in value]),
"upper": lambda value: str(value).upper(),
Expand Down
108 changes: 108 additions & 0 deletions tests/advanced_elem.lgx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
1 if True else 0
#expect:1

1 if False else 0
#expect:0

"a" if True else "b"
#expect:"a"

"a" if False else "b"
#expect:"b"

##################################

[x for x in range(5)]
#expect:[0, 1, 2, 3, 4]

[x for x in range(5) if x % 2 == 0]
#expect:[0, 2, 4]

[x*2 for x in range(3)]
#expect:[0, 2, 4]

[x for x in [1, 2, 3] if x > 1]
#expect:[2, 3]

#bug: AssertionError
#[x for x in "abc"]
##expect:["a", "b", "c"]

#bug: LogicsParseException
#[x.upper() for x in "abc"]
##expect:["A", "B", "C"]

##################################

#bug: AssertionError: assert '2' == '[1, 2]'
#[1, 2, 3, 4][:2]
##expect:[1, 2]

#bug: AssertionError: assert '3' == '[2, 3]'
#[1, 2, 3, 4][1:3]
##expect:[2, 3]

#bug: AssertionError
#"abcdef"[:3]
##expect:"abc"

#bug: AssertionError
#'abcdef'[2:]
##expect:'cdef'

#bug: AssertionError
#'abcdef'[::2]
##expect:'ace'

#bug: AssertionError
#[1, 2, 3, 4][::-1]
##expect:[4, 3, 2, 1]

##################################

[1, 2, 3][1]
#expect:2

"abc"[1]
#expect:"b"

(1, 2, 3)[2]
#expect:3

#bug: logics.parser.LogicsParseException: Line 1, column 1: Parse error, expecting 'Identifier', 'Number', 'String', 'not', '+', '-', '~', '(', '[', 'True', 'False', 'None', '$'
#{"a": 1, "b": 2}["b"]
##expect:2

#bug: logics.parser.LogicsParseException: Line 1, column 2: Parse error, expecting 'Identifier', 'Number', 'String', 'not', '+', '-', '~', '(', '[', 'True', 'False', 'None', '$'
#[{"a": 1}, {"b": 2}][1]["b"]
##expect:2

#bug: logics.parser.LogicsParseException
#{'key': 'value'}['key']
##expect:'value'

##################################

#bug: AssertionError: assert '2' == '[1, 2]'
#[1, 2, 3, 4][:2]
##expect:[1, 2]

#bug: AssertionError...
#[1, 2, 3, 4][1:3]
##expect:[2, 3]

#bug: AssertionError...
#'abcdef'[:3]
##expect:'abc'

#bug: AssertionError...
#'abcdef'[2:]
##expect:'cdef'

#bug: AssertionError...
#'abcdef'[::2]
##expect:'ace'

#bug: AssertionError...
#[1, 2, 3, 4][::-1]
##expect:[4, 3, 2, 1]
123 changes: 123 additions & 0 deletions tests/arithmetic_op.lgx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
5 + 3
#expect:8

"a" + "b"
#expect:"ab"

1 + "b"
#expect:"1b"

1 + 2 + 3 + 4
#expect:10

5 + 0
#expect:5

0 + 0
#expect:0

##################################

5 - 3
#expect:2

5 - 0
#expect:5

0 - 5
#expect:-5

-5 - 5
#expect:-10

0 - 0
#expect:0

"ab" - "b"
#expect:0

##################################

5 * 3
#expect:15

5 * 0
#expect:0

0 * 0
#expect:0

3 * "HelloWorld"
#EXPECT:"HelloWorldHelloWorldHelloWorld"

#bug: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
#[1, 2] * 2
##expect:[1, 2, 1, 2]

##################################

6 / 3
#expect:2

5 / 2
#expect:2.5

5 / 1
#expect:5

0 / 5
#expect:0

5 / 0
#expect:"#ERR:division by zero"

##################################

6 // 3
#expect:2

5 // 2
#expect:2

5 // 1
#expect:5

0 // 5
#expect:0

5 // 0
#expect:"#ERR:division by zero"

##################################

5 % 3
#expect:2

5 % 2
#expect:1

5 % 1
#expect:0

0 % 5
#expect:0

5 % 0
#expect:"#ERR:modulo by zero"

##################################

2 ** 3
#expect:8

5 ** 2
#expect:25

5 ** 1
#expect:5

5 ** 0
#expect:1

0 ** 5
#expect:0
104 changes: 104 additions & 0 deletions tests/data_types.lgx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
int("5")
#expect:5

int(5.5)
#expect:5

int("0")
#expect:0

int(False)
#expect:0

#bug: AssertionError
#int("10", 2)
##expect:2

#bug: AssertionError
#int(True)
##expect:1

#set:numbers:(1,2,3, 53.2)

3 in numbers
#expect:True

4 in numbers
#expect:False

4 not in numbers
#expect:True

"a" in numbers
#expect:False

##################################

float("5.5")
#expect:5.5

#bug: AssertionError
#float(5)
##expect:5.0

#bug: AssertionError
#float("0")
##expect:0.0

#bug: AssertionError
#float(True)
##expect:1.0

#bug: AssertionError
#float(False)
##expect:0.0

#bug: AssertionError
#float("nan")
##expect:float("nan")

##################################

str(True)
#expect:"True"

str(False)
#expect:"False"

str(None)
#expect:"None"

str([1, 2, 3])
#expect:"[1, 2, 3]"

#bug: AssertionError
#str(5)
##expect:5

str(5)
#expect:"5"

str(5.5)
#expect:"5.5"

#set:strings:("a","b","c")

"a" in strings
#expect:True

"aa" in strings
#expect:False

"x" not in strings
#expect:True

#set:string:"Hello World"

"World" in string
#expect:True

"Earth" in string
#expect:False

"Earth" not in string
#expect:True
8 changes: 0 additions & 8 deletions tests/expressions.lgx

This file was deleted.

4 changes: 2 additions & 2 deletions tests/function_calls.lgx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
foo()
#EXPECT:"#ERR:Call to unknown function foo()"
#expect:"#ERR:Call to unknown function foo()"

upper()
#EXPECT:"#ERR:Invalid call to upper()"
#expect:"#ERR:Invalid call to upper()"
4 changes: 0 additions & 4 deletions tests/if.lgx

This file was deleted.

25 changes: 25 additions & 0 deletions tests/if_else_con.lgx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"yes" if 2 + 3 == 5 else "no"
#expect:"yes"

"yes" if False else "no"
#expect:"no"

1 if True else 0
#expect:1

1 if False else 0
#expect:0

1 if 1 else 0
#expect:1

1 if 0 else 0
#expect:0

1 if None else 0
#expect:0

1 if not None else 0
#expect:1

##################################
Loading