testassignment.py :  » Language-Interface » VB-to-Python-Converter » vb2py-0.2 » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » VB to Python Converter 
VB to Python Converter » vb2py 0.2 » test » testassignment.py
# 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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.