/* ----------------------------------------------------------------------------- Copyright 2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] testcase "ParseChars tests" { success } unittest floatNoDecimal { \ UtilTesting.checkSuccessBetween(ParseChars.float("123"),122.9,123.1) } unittest floatDecimalLeft { \ UtilTesting.checkSuccessBetween(ParseChars.float(".123"),0.1229,0.1231) } unittest floatDecimalRight { \ UtilTesting.checkSuccessBetween(ParseChars.float("123."),122.9,123.1) } unittest floatDecimalMiddle { \ UtilTesting.checkSuccessBetween(ParseChars.float("123.456"),123.4559,123.4561) } unittest floatLeadingTrailingZeros { \ UtilTesting.checkSuccessBetween(ParseChars.float("000123.456000"),123.4559,123.4561) } unittest floatNegative { \ UtilTesting.checkSuccessBetween(ParseChars.float("-123.456"),-123.4561,-123.4559) } unittest floatPositive { \ UtilTesting.checkSuccessBetween(ParseChars.float("+123.456"),123.4559,123.4561) } unittest floatNegativeDecimalLeft { \ UtilTesting.checkSuccessBetween(ParseChars.float("-.456"),-0.4561,-0.4559) } unittest floatExponentNoDecimal { \ UtilTesting.checkSuccessBetween(ParseChars.float("123E5"),122.9E5,123.1E5) } unittest floatNegativeExponent { \ UtilTesting.checkSuccessBetween(ParseChars.float("123E-5"),122.9E-5,123.1E-5) } unittest floatPositiveExponent { \ UtilTesting.checkSuccessBetween(ParseChars.float("123E+5"),122.9E5,123.1E5) } unittest floatExponentDecimalRight { \ UtilTesting.checkSuccessBetween(ParseChars.float("123.E5"),122.9E5,123.1E5) } unittest floatExponentDecimalLeft { \ UtilTesting.checkSuccessBetween(ParseChars.float(".123E5"),122.9E2,123.1E2) } unittest floatExponentDecimalMiddle { \ UtilTesting.checkSuccessBetween(ParseChars.float("123.456E5"),123.4559E5,123.4561E5) } unittest floatEmpty { \ UtilTesting.checkError(ParseChars.float("")) } unittest floatNoDigits { \ UtilTesting.checkError(ParseChars.float(".")) } unittest floatTwoDecimals { \ UtilTesting.checkError(ParseChars.float("1.1.")) } unittest floatExponentNoDigitsNoDecimal { \ UtilTesting.checkError(ParseChars.float("E5")) } unittest floatExponentNoDigitsDecimal { \ UtilTesting.checkError(ParseChars.float(".E5")) } unittest floatExponentNoDigitsSign { \ UtilTesting.checkError(ParseChars.float("-E5")) } unittest floatDecimalAfterExponent { \ UtilTesting.checkError(ParseChars.float("1E.5")) } unittest floatExponentExcessData { \ UtilTesting.checkError(ParseChars.float("123E5Q")) } unittest int { \ UtilTesting.checkSuccess(ParseChars.int("1234"),1234) } unittest intNegative { \ UtilTesting.checkSuccess(ParseChars.int("-1234"),-1234) } unittest intPositive { \ UtilTesting.checkSuccess(ParseChars.int("+1234"),1234) } unittest intLeadingZeros { \ UtilTesting.checkSuccess(ParseChars.int("001234"),1234) } unittest intEmpty { \ UtilTesting.checkError(ParseChars.int("")) } unittest intJustSign { \ UtilTesting.checkError(ParseChars.int("-")) } unittest intBadDigit { \ UtilTesting.checkError(ParseChars.int("12A")) } unittest hexInt { \ UtilTesting.checkSuccess(ParseChars.hexInt("12AbCdEf"),\x12ABCDEF) } unittest hexIntNegative { \ UtilTesting.checkSuccess(ParseChars.hexInt("-12AbCdEf"),-\x12ABCDEF) } unittest hexIntPositive { \ UtilTesting.checkSuccess(ParseChars.hexInt("+12AbCdEf"),\x12ABCDEF) } unittest hexIntLeadingZeros { \ UtilTesting.checkSuccess(ParseChars.hexInt("0012AbCdEf"),\x12ABCDEF) } unittest hexIntEmpty { \ UtilTesting.checkError(ParseChars.hexInt("")) } unittest hexIntJustSign { \ UtilTesting.checkError(ParseChars.hexInt("-")) } unittest hexIntBadDigit { \ UtilTesting.checkError(ParseChars.hexInt("12Q")) } unittest octInt { \ UtilTesting.checkSuccess(ParseChars.octInt("127"),\o127) } unittest octIntNegative { \ UtilTesting.checkSuccess(ParseChars.octInt("-127"),-\o127) } unittest octIntPositive { \ UtilTesting.checkSuccess(ParseChars.octInt("+127"),\o127) } unittest octIntLeadingZeros { \ UtilTesting.checkSuccess(ParseChars.octInt("00127"),\o127) } unittest octIntEmpty { \ UtilTesting.checkError(ParseChars.octInt("")) } unittest octIntJustSign { \ UtilTesting.checkError(ParseChars.octInt("-")) } unittest octIntBadDigit { \ UtilTesting.checkError(ParseChars.octInt("19")) } unittest binInt { \ UtilTesting.checkSuccess(ParseChars.binInt("100101"),\b100101) } unittest binIntNegative { \ UtilTesting.checkSuccess(ParseChars.binInt("-100101"),-\b100101) } unittest binIntPositive { \ UtilTesting.checkSuccess(ParseChars.binInt("+100101"),\b100101) } unittest binIntLeadingZeros { \ UtilTesting.checkSuccess(ParseChars.binInt("00100101"),\b100101) } unittest binIntEmpty { \ UtilTesting.checkError(ParseChars.binInt("")) } unittest binIntJustSign { \ UtilTesting.checkError(ParseChars.binInt("-")) } unittest binIntBadDigit { \ UtilTesting.checkError(ParseChars.binInt("12")) }