# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo
from unittest import *
from testframework import *
# << Assignment tests >> (1 of 5)
numeric = [
('a=10', {'a' : 10}),
('b=10.34', {'b' : 10.34}),
('c=10e5', {'c' : 10e5}),
('d=-1', {'d' :-1}),
('e=-10.765', {'e' : -10.765}),
('f=-12.4e4', {'f' : -12.4e4}),
('g=1.0e-45', {'g' : 1.0e-45}),
('h=-1e-8', {'h' :-1e-8}),
('i=&HFF', {'i' :255}),
('j=&HFF&', {'j' :255}),
]
strings = [
('a="a"', {'a' : "a"}),
('b="abcdef"', {'b' : "abcdef"}),
("""c="'" """, {'c' : "'"}),
('d="g\"\"h\"\"j"""', {'d' : 'g"h"j"'}),
(r'd="\"', {'d' : '\\'}), # Trailing single \ is tough
(r'd="hello\not"', {'d' : r'hello\not'}),
]
tests.extend(numeric)
tests.extend(strings)
# << Assignment tests >> (2 of 5)
numeric_exp = [
('a=10+20', {'a' : 30}),
('b=10.5+20.5', {'b' : 31}),
('c=(10+20)/6+2', {'c' : 7}),
('d=(((4*5)/2+10)-10)', {'d' : 10}),
('e=-(10*10)', {'e' : -100}),
('f=-10*10', {'f' : -100}),
('g=&HFF', {'g' : 255}),
('h=5^2', {'h' : 25}),
]
string_exp = [
('a="hello" & "world"', {'a' : "helloworld"}),
]
tests.extend(numeric_exp)
tests.extend(string_exp)
# << Assignment tests >> (3 of 5)
# Tough to test this one - just create a collection and check it has no length
tests.append(("""
Set _a = New Collection
l = len(_a)
""", {"l" : 0}))
tests.append(("""
Set _a = New Collection
Set _b = _a
l1 = len(_a)
l2 = len(_b)
""", {"l1" : 0, "l2" : 0}))
# << Assignment tests >> (4 of 5)
tests.extend([
('a%=10', {'a' : 10}),
('a&=10', {'a' : 10}),
('a#=10', {'a' : 10}),
('a$="10"', {'a' : "10"}),
])
tests.extend([
('a=10%', {'a' : 10}),
('a=10#', {'a' : 10}),
('a=10&', {'a' : 10}),
])
# << Assignment tests >> (5 of 5)
tests.extend([
('a=0 Or 0', {'a' : 0}),
('a=1 Or 0', {'a' : 1}),
('a=0 Or 1', {'a' : 1}),
('a=1 Or 1', {'a' : 1}),
('a=0 And 0', {'a' : 0}),
('a=1 And 0', {'a' : 0}),
('a=0 And 1', {'a' : 0}),
('a=1 And 1', {'a' : 1}),
('a=0 Or Not 0', {'a' : 1}),
('a=1 Or Not 0', {'a' : 1}),
('a=0 Or Not 1', {'a' : 0}),
('a=1 Or Not 1', {'a' : 1}),
('a=0 And Not 0', {'a' : 0}),
('a=1 And Not 0', {'a' : 1}),
('a=0 And Not 1', {'a' : 0}),
('a=1 And Not 1', {'a' : 0}),
('a=Not 0 Or 0', {'a' : 1}),
('a=Not 1 Or 0', {'a' : 0}),
('a=Not 0 Or 1', {'a' : 1}),
('a=Not 1 Or 1', {'a' : 1}),
('a=Not 0 And 0', {'a' : 0}),
('a=Not 1 And 0', {'a' : 0}),
('a=Not 0 And 1', {'a' : 1}),
('a=Not 1 And 1', {'a' : 0}),
('a=Not 0 Or Not 0', {'a' : 1}),
('a=Not 1 Or Not 0', {'a' : 1}),
('a=Not 0 Or Not 1', {'a' : 1}),
('a=Not 1 Or Not 1', {'a' : 0}),
('a=Not 0 And Not 0', {'a' : 1}),
('a=Not 1 And Not 0', {'a' : 0}),
('a=Not 0 And Not 1', {'a' : 0}),
('a=Not 1 And Not 1', {'a' : 0}),
])
tests.extend([
("""
Dim _a As Object
If _a Is Nothing Then
b = 1
Else
b = 2
End If
""", {"b" : 1}),
("""
Dim _a As Object
Set _a = New Collection
If _a Is Nothing Then
b = 1
Else
b = 2
End If
""", {"b" : 2}),
("""
Dim _a As Object
Set _a = New Collection
Set _a = Nothing
If _a Is Nothing Then
b = 1
Else
b = 2
End If
""", {"b" : 1}),
])
# -- end -- << Assignment tests >>
import vb2py.vbparser
vb2py.vbparser.log.setLevel(0) # Don't print all logging stuff
TestClass = addTestsTo(BasicTest, tests)
if __name__ == "__main__":
main()
|