1111from sphinxcontrib .chapeldomain import (
1212 ChapelDomain , ChapelModuleIndex , ChapelClassObject , ChapelModuleLevel , ChapelObject ,
1313 ChapelTypedField , ChapelClassMember ,
14- chpl_sig_pattern , match_chpl_sig_pattern , chpl_attr_sig_pattern ,
14+ chpl_sig_pattern , match_chpl_sig_pattern ,
15+ chpl_attr_sig_pattern , match_chpl_attr_sig_pattern
1516)
1617
1718
@@ -892,16 +893,23 @@ class AttrSigPatternTests(PatternTestCase):
892893
893894 pattern = chpl_attr_sig_pattern
894895
895- def check_sig (self , sig , func_prefix , name_prefix , name , retann ):
896+ def check_sig (self , sig , func_prefix , name_prefix , name , type_ , default_value ):
896897 """Verify signature results in appropriate matches."""
897- match = self . pattern . match (sig )
898+ match = match_chpl_attr_sig_pattern (sig )
898899 self .assertIsNotNone (match )
899900
900- (actual_func_prefix , actual_name_prefix , actual_name , actual_retann ) = match .groups ()
901+ (
902+ actual_func_prefix ,
903+ actual_name_prefix ,
904+ actual_name ,
905+ actual_type ,
906+ actual_default_value ,
907+ ) = match
901908 self .assertEqual (func_prefix , actual_func_prefix )
902909 self .assertEqual (name_prefix , actual_name_prefix )
903910 self .assertEqual (name , actual_name )
904- self .assertEqual (retann , actual_retann )
911+ self .assertEqual (type_ , actual_type )
912+ self .assertEqual (default_value , actual_default_value )
905913
906914 def test_does_not_match (self ):
907915 """Verify various signatures that should not match."""
@@ -927,7 +935,7 @@ def test_simple_label(self):
927935 '1' ,
928936 ]
929937 for sig in test_cases :
930- self .check_sig (sig , '' , None , sig , None )
938+ self .check_sig (sig , '' , None , sig , None , None )
931939
932940 def test_with_class_names (self ):
933941 """Verify symbols with class names match pattern."""
@@ -937,7 +945,7 @@ def test_with_class_names(self):
937945 ('BigNum.fromInt' , 'BigNum.' , 'fromInt' ),
938946 ]
939947 for sig , class_name , attr in test_cases :
940- self .check_sig (sig , '' , class_name , attr , None )
948+ self .check_sig (sig , '' , class_name , attr , None , None )
941949
942950 def test_with_prefixes (self ):
943951 """Verify type, config, etc prefixes work."""
@@ -949,51 +957,62 @@ def test_with_prefixes(self):
949957 ('const baz' , 'const ' , 'baz' ),
950958 ]
951959 for sig , prefix , attr in test_cases :
952- self .check_sig (sig , prefix , None , attr , None )
960+ self .check_sig (sig , prefix , None , attr , None , None )
953961
954962 def test_with_types (self ):
955963 """Verify types parse correctly."""
956964 test_cases = [
957- ('foo: int' , 'foo' , ': int' ),
958- ('bar: real' , 'bar' , ': real' ),
959- ('baz: int(32)' , 'baz' , ': int(32)' ),
960- ('D: domain(9)' , 'D' , ': domain(9)' ),
961- ('A: [{1..n}] BigNum' , 'A' , ': [{1..n}] BigNum' ),
962- ('x: MyModule.MyClass' , 'x' , ': MyModule.MyClass' ),
963- ('x : sync real' , 'x' , ' : sync real' ),
965+ ('foo: int' , 'foo' , 'int' , None ),
966+ ('bar: real' , 'bar' , 'real' , None ),
967+ ('baz: int(32)' , 'baz' , 'int(32)' , None ),
968+ ('D: domain(9)' , 'D' , 'domain(9)' , None ),
969+ ('A: [{1..n}] BigNum' , 'A' , '[{1..n}] BigNum' , None ),
970+ ('x: MyModule.MyClass' , 'x' , 'MyModule.MyClass' , None ),
971+ ('x : sync real' , 'x' , 'sync real' , None ),
972+ ]
973+ for sig , attr , type_name , default_val in test_cases :
974+ self .check_sig (sig , '' , None , attr , type_name , default_val )
975+
976+ def test_with_defaults (self ):
977+ """Verify default values parse correctly."""
978+ test_cases = [
979+ ('x = 5' , 'x' , None , '= 5' ),
980+ ('y = [i in 1..10] i == 1' , 'y' , None , '= [i in 1..10] i == 1' ),
981+ ('z { A=1, B}' , 'z' , None , '{ A=1, B}' ),
964982 ]
965- for sig , attr , type_name in test_cases :
966- self .check_sig (sig , '' , None , attr , type_name )
983+ for sig , attr , type_name , default_val in test_cases :
984+ self .check_sig (sig , '' , None , attr , type_name , default_val )
967985
968986 def test_with_all (self ):
969987 """Verify full specified signatures parse correctly."""
970988 test_cases = [
971- ('config const MyModule.MyClass.n: int' , 'config const ' , 'MyModule.MyClass.' , 'n' , ': int' ),
972- ('var X.n: MyMod.MyClass' , 'var ' , 'X.' , 'n' , ': MyMod.MyClass' ),
973- ('config param debugAdvancedIters:bool' , 'config param ' , None , 'debugAdvancedIters' , ':bool' ),
974- ('config param MyMod.DEBUG: bool' , 'config param ' , 'MyMod.' , 'DEBUG' , ': bool' ),
975- ('var RandomStreamPrivate_lock$: _syncvar(bool)' , 'var ' , None , 'RandomStreamPrivate_lock$' , ': _syncvar(bool)' ),
976- ('var RandomStreamPrivate_lock$: sync bool' , 'var ' , None , 'RandomStreamPrivate_lock$' , ': sync bool' ),
977- ('const RS$.lock$: sync MyMod$.MyClass$.bool' , 'const ' , 'RS$.' , 'lock$' , ': sync MyMod$.MyClass$.bool' ),
978- ('type commDiagnostics = chpl_commDiagnostics' , 'type ' , None , 'commDiagnostics' , ' = chpl_commDiagnostics' ),
979- ('type age = int(64)' , 'type ' , None , 'age' , ' = int(64)' ),
980- ('type MyMod.BigAge=BigNum.BigInt' , 'type ' , 'MyMod.' , 'BigAge' , '=BigNum.BigInt' ),
981- ('const x = false' , 'const ' , None , 'x' , ' = false' ),
982- ('config const MyC.x: int(64) = 5' , 'config const ' , 'MyC.' , 'x' , ': int(64) = 5' ),
983- ('config param n: uint(64) = 5: uint(64)' , 'config param ' , None , 'n' , ': uint(64) = 5: uint(64)' ),
984- ('var MyM.MyC.x = 4: uint(64)' , 'var ' , 'MyM.MyC.' , 'x' , ' = 4: uint(64)' ),
985- ('type MyT = 2*real(64)' , 'type ' , None , 'MyT' , ' = 2*real(64)' ),
986- ('type myFloats = 2*(real(64))' , 'type ' , None , 'myFloats' , ' = 2*(real(64))' ),
987- ('enum Color { Red, Yellow, Blue }' , 'enum ' , None , 'Color' , ' { Red, Yellow, Blue }' ),
988- ('enum Month { January=1, February }' , 'enum ' , None , 'Month' , ' { January=1, February }' ),
989- ('enum One { Neo }' , 'enum ' , None , 'One' , ' { Neo }' ),
990- ('enum constant Pink' , 'enum constant ' , None , 'Pink' , None ),
991- ('enum constant December' , 'enum constant ' , None , 'December' , None ),
992- ('enum constant Hibiscus' , 'enum constant ' , None , 'Hibiscus' , None ),
993- ('enum constant Aquarius' , 'enum constant ' , None , 'Aquarius' , None )
989+ ('config const MyModule.MyClass.n: int' , 'config const ' , 'MyModule.MyClass.' , 'n' , 'int' , None ),
990+ ('var X.n: MyMod.MyClass' , 'var ' , 'X.' , 'n' , 'MyMod.MyClass' , None ),
991+ ('config param debugAdvancedIters:bool' , 'config param ' , None , 'debugAdvancedIters' , 'bool' , None ),
992+ ('config param MyMod.DEBUG: bool' , 'config param ' , 'MyMod.' , 'DEBUG' , 'bool' , None ),
993+ ('var RandomStreamPrivate_lock$: _syncvar(bool)' , 'var ' , None , 'RandomStreamPrivate_lock$' , '_syncvar(bool)' , None ),
994+ ('var RandomStreamPrivate_lock$: sync bool' , 'var ' , None , 'RandomStreamPrivate_lock$' , 'sync bool' , None ),
995+ ('const RS$.lock$: sync MyMod$.MyClass$.bool' , 'const ' , 'RS$.' , 'lock$' , 'sync MyMod$.MyClass$.bool' , None ),
996+ ('var arr: [{1..10}] real(64) = [i in 1..10] i:real(64)' , 'var ' , None , 'arr' , '[{1..10}] real(64)' , '= [i in 1..10] i:real(64)' ),
997+ ('type commDiagnostics = chpl_commDiagnostics' , 'type ' , None , 'commDiagnostics' , None , '= chpl_commDiagnostics' ),
998+ ('type age = int(64)' , 'type ' , None , 'age' , None , '= int(64)' ),
999+ ('type MyMod.BigAge=BigNum.BigInt' , 'type ' , 'MyMod.' , 'BigAge' , None , '=BigNum.BigInt' ),
1000+ ('const x = false' , 'const ' , None , 'x' , None , '= false' ),
1001+ ('config const MyC.x: int(64) = 5' , 'config const ' , 'MyC.' , 'x' , 'int(64)' , '= 5' ),
1002+ ('config param n: uint(64) = 5: uint(64)' , 'config param ' , None , 'n' , 'uint(64)' , '= 5: uint(64)' ),
1003+ ('var MyM.MyC.x = 4: uint(64)' , 'var ' , 'MyM.MyC.' , 'x' , None , '= 4: uint(64)' ),
1004+ ('type MyT = 2*real(64)' , 'type ' , None , 'MyT' , None , '= 2*real(64)' ),
1005+ ('type myFloats = 2*(real(64))' , 'type ' , None , 'myFloats' , None , '= 2*(real(64))' ),
1006+ ('enum Color { Red, Yellow, Blue }' , 'enum ' , None , 'Color' , None , '{ Red, Yellow, Blue }' ),
1007+ ('enum Month { January=1, February }' , 'enum ' , None , 'Month' , None , '{ January=1, February }' ),
1008+ ('enum One { Neo }' , 'enum ' , None , 'One' , None , '{ Neo }' ),
1009+ ('enum constant Pink' , 'enum constant ' , None , 'Pink' , None , None ),
1010+ ('enum constant December' , 'enum constant ' , None , 'December' , None , None ),
1011+ ('enum constant Hibiscus' , 'enum constant ' , None , 'Hibiscus' , None , None ),
1012+ ('enum constant Aquarius' , 'enum constant ' , None , 'Aquarius' , None , None )
9941013 ]
995- for sig , prefix , class_name , attr , type_name in test_cases :
996- self .check_sig (sig , prefix , class_name , attr , type_name )
1014+ for sig , prefix , class_name , attr , type_name , default_value in test_cases :
1015+ self .check_sig (sig , prefix , class_name , attr , type_name , default_value )
9971016
9981017
9991018if __name__ == '__main__' :
0 commit comments