testdims.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 » testdims.py
# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo

from unittest import *
from testframework import *

# << Dim tests >> (1 of 3)
# Untyped
tests.append(("""
Dim a, b, c
a = 10
b = "hello"
c = 123.5
""", {"a" : 10, "b" : "hello", "c" : 123.5}
))

# Typed
tests.append(("""
Dim a As Integer, b As String, c As Single
a = 10
b = "hello"
c = 123.5
""", {"a" : 10, "b" : "hello", "c" : 123.5}
))

# Array of integers
tests.append(("""
Dim a(3) As Integer
a(0) = 1
a(1) = 2
a(2) = 3
a(3) = 4
""", {"a" : [1,2,3,4]}
))

# Array of integers with non-zero offset
tests.append(("""
Dim a(1 To 3) As Integer
a(1) = 2
a(2) = 3
a(3) = 4
""", {"a" : [2,3,4]}
))

# String size indicator
tests.append(("""
Dim _a As String * 20
b = Len(_a)
""", {"b" : 20}
))
# << Dim tests >> (2 of 3)
# Redims
tests.append(("""
Dim _a() As Single
ReDim _a(10)
b = len(_a)
""", {"b" : 11}))

# Redims without preserving
tests.append(("""
Dim _a(10) As Single
_a(5) = 10
ReDim _a(10)
b = 0 + _a(5)
""", {"b" : 0}))

# Redims with preserving
tests.append(("""
Dim _a(10) As Single
_a(5) = 10
ReDim Preserve _a(10)
b = 0 + _a(5)
""", {"b" : 10}))

# Redims with preserving
tests.append(("""
Dim _a(10, 5) As Single
_a(5, 1) = 10
_a(8, 4) = 20
ReDim Preserve _a(20, 10)
b = _a(5, 1)
c = _a(8, 4)
""", {"b" : 10, "c" : 20}))

# Redims with preserving
tests.append(("""
Dim _a(10) As Single
_a(5) = 10
_a(8) = 10
ReDim Preserve _a(5)
b = _a(5)
""", {"b" : 10}))
# << Dim tests >> (3 of 3)
# Double dim!
tests.append(("""
Dim _a(10), _b(10)
for _i = 1 To 10
   _a(_i) = _i+1
   _b(_i) = _i*10
Next _i
'
c = _b(_a(1))
d = _b(_a(2))
""", {"c" : 20, "d" : 30}
))

# Double dim set 
tests.append(("""
Dim _a(10), _b(10)
for _i = 1 To 10
   _a(_i) = _i+1
   _b(_i) = _i*10
Next _i
'
_b(_a(1)) = 101
_b(_a(2)) = 202
'
c = _b(2)
d = _b(3)
""", {"c" : 101, "d" : 202}
))

# Get Dim Fn!
tests.append(("""
Dim  _b(10)
for _i = 1 To 10
   _b(_i) = _i*10
Next _i
'
Function _a(x)
   _a = x+1
End Function
'
c = _b(_a(1))
d = _b(_a(2))
""", {"c" : 20, "d" : 30}
))

# Set Dim Fn
tests.append(("""
Dim  _b(10)
for _i = 1 To 10
   _b(_i) = _i*10
Next _i
'
Function _a(x)
   _a = x+1
End Function
'
_b(_a(1)) = 101
_b(_a(2)) = 202
'
c = _b(2)
d = _b(3)
""", {"c" : 101, "d" : 202}
))
# -- end -- << Dim 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.