t010.py

00001 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 #
00014 # Regression Test for Issue #10
00015 #
00016 # Create sequence_getSubscript()
00017 #
00018 # The new function is used in BINARY_SUBSCRIPT,
00019 # so this tests the four supported subscript statements
00020 #
00021 
00022 # Test string subscript
00023 s = "test"
00024 assert s[0] == 't'
00025 assert s[-2] == 's'
00026 
00027 # Test tuple subscript
00028 t = (4, 2)
00029 assert t[1] == 2
00030 assert t[-2] == 4
00031 
00032 # Test list subscript
00033 l = [2, 5, 6]
00034 assert l[2] == 6
00035 assert l[-1] == 6
00036 
00037 # Test dict subscript
00038 d = {0:0, 1:'t', "2":2}
00039 assert d[0] == 0
00040 assert d[1] == 't'
00041 assert d["2"] == 2
00042 
00043 #
00044 # UNPACK_SEQUENCE also uses seq_getSubscript()
00045 #
00046 a,b,c = (1,2,3)
00047 assert a == 1
00048 assert b == 2
00049 assert c == 3
00050 
00051 c,b,a = [2,5,6]
00052 assert c == 2
00053 assert b == 5
00054 assert a == 6
00055 
00056 #
00057 # #59: Improve bytecode UNPACK_SEQUENCE
00058 #
00059 a,b,c = "256"
00060 assert a == "2"
00061 assert b == "5"
00062 assert c == "6"

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9