@@ -604,12 +604,12 @@ describe("ReludeParse_Parser", () => {
604604 testParse(P . anyDigit |> P . orUnit, "a" , () , {pos: 0 , str: "a" })
605605 );
606606
607- test("optional hit" , () =>
608- testParse(P . anyDigit |> P . optional , "3" , Some ("3" ), {pos: 1 , str: "3" })
607+ test("opt hit" , () =>
608+ testParse(P . anyDigit |> P . opt , "3" , Some ("3" ), {pos: 1 , str: "3" })
609609 );
610610
611- test("optional miss" , () =>
612- testParse(P . anyDigit |> P . optional , "a" , None , {pos: 0 , str: "a" })
611+ test("opt miss" , () =>
612+ testParse(P . anyDigit |> P . opt , "a" , None , {pos: 0 , str: "a" })
613613 );
614614
615615 test("sepBy empty" , () =>
@@ -954,67 +954,217 @@ describe("ReludeParse_Parser", () => {
954954 );
955955
956956 testAll(
957- "anyPositiveInt " ,
957+ "anyUnsignedInt success " ,
958958 [
959959 ("0" , 0 , 1 ),
960960 ("1" , 1 , 1 ),
961961 ("2" , 2 , 1 ),
962962 ("12" , 12 , 2 ),
963963 ("12345" , 12345 , 5 ),
964- ("00" , 0 , 1 ), // 0 parses as int, leaving the remaining
965- ("01" , 0 , 1 ), // 0 parses as int, leaving the remaining
966- ("002" , 0 , 1 ) // 0 parses as int, leaving the remaining
967964 ] ,
968965 ((input, expected, pos)) =>
969- testParse(P . anyInt , input, expected, {pos, str: input})
966+ testParse(P . anyUnsignedInt <* P . eof , input, expected, {pos, str: input})
970967 );
971968
972- testAll("anyPositiveInt fail" , [ "-1" , "-0" , "a" , "!" , ".0" ] , input =>
973- testParseFail(P . anyPositiveInt, input, 0 )
969+ testAll(
970+ "anyUnsignedInt fail" ,
971+ [
972+ ("-1" , 0 ),
973+ ("-0" , 0 ),
974+ ("a" , 0 ),
975+ ("!" , 0 ),
976+ (".0" , 0 ),
977+ ("0." , 1 ),
978+ ("00" , 1 ),
979+ ("01" , 1 ),
980+ ("002" , 1 ),
981+ ] ,
982+ ((input, pos)) =>
983+ testParseFail(P . anyUnsignedInt <* P . eof, input, pos)
974984 );
975985
976986 testAll(
977- "anyNegativeInt" ,
987+ "anyPositiveInt success" ,
988+ [
989+ ("0" , 0 , 1 ),
990+ ("1" , 1 , 1 ),
991+ ("2" , 2 , 1 ),
992+ ("12" , 12 , 2 ),
993+ ("12345" , 12345 , 5 ),
994+ ("+0" , 0 , 2 ),
995+ ("+1" , 1 , 2 ),
996+ ("+2" , 2 , 2 ),
997+ ("+12" , 12 , 3 ),
998+ ("+12345" , 12345 , 6 ),
999+ ] ,
1000+ ((input, expected, pos)) =>
1001+ testParse(P . anyPositiveInt <* P . eof, input, expected, {pos, str: input})
1002+ );
1003+
1004+ testAll(
1005+ "anyPositiveInt fail" ,
1006+ [
1007+ ("-1" , 0 ),
1008+ ("-0" , 0 ),
1009+ ("a" , 0 ),
1010+ ("!" , 0 ),
1011+ (".0" , 0 ),
1012+ ("0." , 1 ),
1013+ ("00" , 1 ),
1014+ ("01" , 1 ),
1015+ ("002" , 1 ),
1016+ ("+00" , 2 ),
1017+ ("+01" , 2 ),
1018+ ("+002" , 2 ),
1019+ ] ,
1020+ ((input, pos)) =>
1021+ testParseFail(P . anyPositiveInt <* P . eof, input, pos)
1022+ );
1023+
1024+ testAll(
1025+ "anyNegativeInt success" ,
9781026 [
9791027 ("-0" , 0 , 2 ),
9801028 ("-1" , (- 1 ), 2 ),
9811029 ("-2" , (- 2 ), 2 ),
9821030 ("-12" , (- 12 ), 3 ),
9831031 ("-12345" , (- 12345 ), 6 ),
984- ("-00" , 0 , 2 ), // 0 parses as int, leaving the remaining
985- ("-01" , 0 , 2 ), // 0 parses as int, leaving the remaining
986- ("-002" , 0 , 2 ) // 0 parses as int, leaving the remaining
9871032 ] ,
9881033 ((input, expected, pos)) =>
989- testParse(P . anyNegativeInt, input, expected, {pos, str: input})
1034+ testParse(P . anyNegativeInt <* P . eof , input, expected, {pos, str: input})
9901035 );
9911036
992- testAll("anyNegativeInt fail" , [ "1" , "0" , "a" , "!" , ".0" ] , input =>
993- testParseFail(P . anyNegativeInt, input, 0 )
1037+ testAll(
1038+ "anyNegativeInt fail" ,
1039+ [
1040+ ("1" , 0 ),
1041+ ("0" , 0 ),
1042+ ("a" , 0 ),
1043+ ("!" , 0 ),
1044+ (".0" , 0 ),
1045+ ("0." , 0 ),
1046+ ("-.0" , 1 ),
1047+ ("-0." , 2 ),
1048+ ("-00" , 2 ),
1049+ ("-01" , 2 ),
1050+ ("-002" , 2 ),
1051+ ] ,
1052+ ((input, pos)) =>
1053+ testParseFail(P . anyNegativeInt <* P . eof, input, pos)
9941054 );
9951055
9961056 testAll(
997- "anyInt" ,
1057+ "anyInt success " ,
9981058 [
9991059 ("0" , 0 , 1 ),
10001060 ("1" , 1 , 1 ),
10011061 ("2" , 2 , 1 ),
10021062 ("12" , 12 , 2 ),
10031063 ("12345" , 12345 , 5 ),
1004- ("00" , 0 , 1 ), // 0 parses as int, leaving the remaining
1005- ("01" , 0 , 1 ), // 0 parses as int, leaving the remaining
1006- ("002" , 0 , 1 ), // 0 parses as int, leaving the remaining
10071064 ("-0" , 0 , 2 ),
10081065 ("-1" , (- 1 ), 2 ),
10091066 ("-2" , (- 2 ), 2 ),
10101067 ("-12" , (- 12 ), 3 ),
10111068 ("-12345" , (- 12345 ), 6 ),
1012- ("-00" , 0 , 2 ), // 0 parses as int, leaving the remaining
1013- ("-01" , 0 , 2 ), // 0 parses as int, leaving the remaining
1014- ("-002" , 0 , 2 ) // 0 parses as int, leaving the remaining
10151069 ] ,
10161070 ((input, expected, pos)) =>
1017- testParse(P . anyInt, input, expected, {pos, str: input})
1071+ testParse(P . anyInt <* P . eof, input, expected, {pos, str: input})
1072+ );
1073+
1074+ testAll(
1075+ "anyInt fail" ,
1076+ [
1077+ ("a" , 0 ),
1078+ ("!" , 0 ),
1079+ (".0" , 0 ),
1080+ ("0." , 1 ),
1081+ ("-0." , 2 ),
1082+ ("00" , 1 ),
1083+ ("01" , 1 ),
1084+ ("002" , 1 ),
1085+ ("-00" , 2 ),
1086+ ("-01" , 2 ),
1087+ ("-002" , 2 ),
1088+ ] ,
1089+ ((input, pos)) =>
1090+ testParseFail(P . anyInt <* P . eof, input, pos)
1091+ );
1092+
1093+ testAll(
1094+ "anyDecimal success" ,
1095+ [
1096+ ("0" , "0" , 1 ),
1097+ ("1" , "1" , 1 ),
1098+ ("12" , "12" , 2 ),
1099+ (".0" , ".0" , 2 ),
1100+ (".00" , ".00" , 3 ),
1101+ (".001" , ".001" , 4 ),
1102+ ("0.0" , "0.0" , 3 ),
1103+ ("0.00" , "0.00" , 4 ),
1104+ ("0.000" , "0.000" , 5 ),
1105+ ("0.001" , "0.001" , 5 ),
1106+ ("1.000" , "1.000" , 5 ),
1107+ ("1.002" , "1.002" , 5 ),
1108+ ("9.87e3" , "9.87e3" , 6 ),
1109+ ("9.87e33" , "9.87e33" , 7 ),
1110+ ("9.87e-3" , "9.87e-3" , 7 ),
1111+ ("9.87e-33" , "9.87e-33" , 8 ),
1112+ ("9.87E3" , "9.87E3" , 6 ),
1113+ ("9.87E33" , "9.87E33" , 7 ),
1114+ ("9.87E-3" , "9.87E-3" , 7 ),
1115+ ("9.87E-33" , "9.87E-33" , 8 ),
1116+ ] ,
1117+ ((str, expected, pos)) =>
1118+ testParse(P . anyDecimal <* P . eof, str, expected, {pos, str})
1119+ );
1120+
1121+ testAll(
1122+ "anyDecimal failure" ,
1123+ [
1124+ ("0." , 1 ), // This could arguably parse, but it doesn't right now
1125+ ("a" , 0 ),
1126+ ("-a" , 1 ),
1127+ ("!" , 0 ),
1128+ (".0a" , 2 ),
1129+ ("-0.a" , 2 ),
1130+ ("0.a" , 1 ),
1131+ ("1.2e-a" , 3 ),
1132+ ] ,
1133+ ((str, pos)) =>
1134+ testParseFail(P . anyDecimal <* P . eof, str, pos)
1135+ );
1136+
1137+ testAll(
1138+ "boolTrue" ,
1139+ [ ("true" , true , 4 ), ("TRUE" , true , 4 ), ("TrUe" , true , 4 )] ,
1140+ ((str, exp, pos)) =>
1141+ testParse(P . boolTrue <* P . eof, str, exp, {str, pos})
1142+ );
1143+
1144+ testAll(
1145+ "boolFalse" ,
1146+ [ ("false" , false , 5 ), ("FALSE" , false , 5 ), ("fALse" , false , 5 )] ,
1147+ ((str, exp, pos)) =>
1148+ testParse(P . boolFalse <* P . eof, str, exp, {str, pos})
1149+ );
1150+
1151+ testAll(
1152+ "anyBool success" ,
1153+ [
1154+ ("true" , true , 4 ),
1155+ ("TRUE" , true , 4 ),
1156+ ("TrUe" , true , 4 ),
1157+ ("false" , false , 5 ),
1158+ ("FALSE" , false , 5 ),
1159+ ("fALse" , false , 5 ),
1160+ ] ,
1161+ ((str, exp, pos)) =>
1162+ testParse(P . anyBool <* P . eof, str, exp, {str, pos})
1163+ );
1164+
1165+ testAll(
1166+ "anyBool false" , [ ("tru" , 0 ), ("fal" , 0 ), ("a" , 0 )] , ((str, pos)) =>
1167+ testParseFail(P . anyBool <* P . eof, str, pos)
10181168 );
10191169
10201170 test("anyStr empty" , () =>
@@ -1376,4 +1526,31 @@ describe("ReludeParse_Parser", () => {
13761526 {pos: 9 , str: "< 456 >" },
13771527 )
13781528 );
1529+
1530+ test("betweenDoubleQuotes" , () =>
1531+ testParse(
1532+ P . betweenDoubleQuotes(P . anyNonEmptyDigits),
1533+ "\" 123\" " ,
1534+ "123" ,
1535+ {pos: 5 , str: "\" 123\" " },
1536+ )
1537+ );
1538+
1539+ test("betweenSingleQuotes" , () =>
1540+ testParse(
1541+ P . betweenSingleQuotes(P . anyNonEmptyDigits),
1542+ "'123'" ,
1543+ "123" ,
1544+ {pos: 5 , str: "'123'" },
1545+ )
1546+ );
1547+
1548+ test("betweenBackTicks" , () =>
1549+ testParse(
1550+ P . betweenBackTicks(P . anyNonEmptyDigits),
1551+ "`123`" ,
1552+ "123" ,
1553+ {pos: 5 , str: "`123`" },
1554+ )
1555+ );
13791556});
0 commit comments