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

from unittest import *
from testframework import *

# << Sub tests >> (1 of 4)
# Simple subroutine - use "global" to see results of the subroutine
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Value As String)
  _lst(Index) = Value
End Sub

_SetValue 5, "hello"
a = _lst(5)
""", {"a" : "hello"}))

# Simple subroutine with an exit
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Value1 As String, Value2 As String)
  _lst(Index) = Value1
  Exit Sub
  _lst(Index) = Value2
End Sub

_SetValue 5, "hello", "bye"
a = _lst(5)
""", {"a" : "hello"}))

# Simple sub calling a sub
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Value As String)
  _lst(Index) = Value
End Sub

Sub _SetFive(Value)
  _SetValue 5, Value
End Sub

_SetFive "hello"
a = _lst(5)
""", {"a" : "hello"}))

# Subroutine empty but for a comment - this can be a syntax error in Python
tests.append(("""
Sub _SetValue()
  ' Nothing to see here
End Sub
""", {}))
# << Sub tests >> (2 of 4)
# Recursive sub
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Value)
  _lst(Index) = Value
  If Index < 10 Then 
    _SetValue Index+1, Value+1
  End If
End Sub

_SetValue 1, 1
a = _lst(5)
""", {"a" : 5}))
# << Sub tests >> (3 of 4)
# Optional arguments
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Optional Value=10)
  _lst(Index) = Value
End Sub

_SetValue 5, "hello"
_SetValue 6
a = _lst(5)
b = _lst(6)
""", {"a" : "hello", "b" : 10}))

# Optional arguments
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Optional Value)
  If IsMissing(Value) Then Value = 10
  _lst(Index) = Value
End Sub

_SetValue 5, "hello"
_SetValue 6
a = _lst(5)
b = _lst(6)
""", {"a" : "hello", "b" : 10}))

# Optional arguments with hex numbers
tests.append(("""
Dim _lst(10) As Single
Sub _SetValue(Index As Integer, Optional Value=&HA)
  _lst(Index) = Value
End Sub

_SetValue 5, "hello"
_SetValue 6
a = _lst(5)
b = _lst(6)
""", {"a" : "hello", "b" : 10}))
# << Sub tests >> (4 of 4)
# Sub with named arguments
tests.append(("""
Dim _vals(10)
Sub _sum(Optional x=1, Optional y=2, Optional z=3)
  _vals(1) = x + y + z
End Sub

_sum 10, 20, 30
a = _vals(1)
_sum x:=10
b = _vals(1)
_sum z:=10 
c = _vals(1)
_sum
d = _vals(1)
_sum x:=10, y:=20, z:=30
f = _vals(1)
""", {"a" : 60, "b" : 15, "c" : 13, "d" : 6, "f" : 60}))
# -- end -- << Sub 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.