Changeset 1782 for trunk


Ignore:
Timestamp:
Jun 28, 2010, 12:19:11 PM (14 years ago)
Author:
dkearney
Message:

patching units code to ignore whitespace within unit strings. adding test cases to the units test suite. this patch is in regard to nanohub ticket #257716

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/tcl/tests/units.test

    r1740 r1782  
    10481048} {0 sK 0 time*temperature}
    10491049
     1050#--------------------------------------------------------------------
     1051# Allow isspace whitespace in Rappture::Units
     1052#--------------------------------------------------------------------
     1053
     1054test space-7.0.0.1 {check for spaces before value unit string} {
     1055    list [catch {Rappture::Units::Search::for " 300K"} msg] $msg
     1056} {0 K}
     1057
     1058test space-7.0.0.2 {check for spaces after value unit string} {
     1059    list [catch {Rappture::Units::Search::for "300K "} msg] $msg
     1060} {0 K}
     1061
     1062test space-7.0.0.3 {check for spaces before and after value unit string} {
     1063    list [catch {Rappture::Units::Search::for " 300K "} msg] $msg
     1064} {0 K}
     1065
     1066test space-7.0.0.4 {check for spaces between value and unit string} {
     1067    list [catch {Rappture::Units::Search::for " 300 K "} msg] $msg
     1068} {0 K}
     1069
     1070test space-7.0.0.5 {check for spaces between value and single unit string} {
     1071    list [catch {Rappture::Units::Search::for "300 K"} msg] $msg
     1072} {0 K}
     1073
     1074test space-7.0.0.6 {check for spaces between value and multiple unit string} {
     1075    list [catch {Rappture::Units::Search::for "300 Kft"} msg] $msg
     1076} {0 Kft}
     1077
     1078test space-7.0.0.7 {check for spaces around and between value and multiple unit string} {
     1079    list [catch {Rappture::Units::Search::for " 300 Kft "} msg] $msg
     1080} {0 Kft}
     1081
     1082test space-7.0.0.8 {check for spaces between multiple unit string} {
     1083    list [catch {Rappture::Units::Search::for "300 K ft"} msg] $msg
     1084} {0 Kft}
     1085
     1086test space-7.0.0.9 {check for spaces around and between multiple unit string} {
     1087    list [catch {Rappture::Units::Search::for " 300 K ft "} msg] $msg
     1088} {0 Kft}
     1089
     1090test space-7.0.0.10 {check for spaces between multiple unit string with division} {
     1091    list [catch {Rappture::Units::Search::for "300 K / ft"} msg] $msg
     1092} {0 K/ft}
     1093
     1094test space-7.0.0.11 {check for spaces between multiple unit string with multiplication} {
     1095    list [catch {Rappture::Units::Search::for "300 K * ft"} msg] $msg
     1096} {0 Kft}
     1097
     1098test space-7.0.1.1 {check for tabs before value unit string} {
     1099    list [catch {Rappture::Units::Search::for "\t300K"} msg] $msg
     1100} {0 K}
     1101
     1102test space-7.0.1.2 {check for tabs after value unit string} {
     1103    list [catch {Rappture::Units::Search::for "300K\t"} msg] $msg
     1104} {0 K}
     1105
     1106test space-7.0.1.3 {check for tabs before and after value unit string} {
     1107    list [catch {Rappture::Units::Search::for "\t300K\t"} msg] $msg
     1108} {0 K}
     1109
     1110test space-7.0.1.4 {check for tabs between value and unit string} {
     1111    list [catch {Rappture::Units::Search::for "\t300\tK\t"} msg] $msg
     1112} {0 K}
     1113
     1114test space-7.0.1.5 {check for tabs between value and single unit string} {
     1115    list [catch {Rappture::Units::Search::for "300\tK"} msg] $msg
     1116} {0 K}
     1117
     1118test space-7.0.1.6 {check for tabs between value and multiple unit string} {
     1119    list [catch {Rappture::Units::Search::for "300\tKft"} msg] $msg
     1120} {0 Kft}
     1121
     1122test space-7.0.1.7 {check for tabs around and between value and multiple unit string} {
     1123    list [catch {Rappture::Units::Search::for "\t300\tKft\t"} msg] $msg
     1124} {0 Kft}
     1125
     1126test space-7.0.1.8 {check for tabs between multiple unit string} {
     1127    list [catch {Rappture::Units::Search::for "300\tK\tft"} msg] $msg
     1128} {0 Kft}
     1129
     1130test space-7.0.1.9 {check for tabs around and between multiple unit string} {
     1131    list [catch {Rappture::Units::Search::for "\t300\tK\tft\t"} msg] $msg
     1132} {0 Kft}
     1133
     1134test space-7.0.1.10 {check for tabs between multiple unit string with division} {
     1135    list [catch {Rappture::Units::Search::for "300\tK\t/\tft"} msg] $msg
     1136} {0 K/ft}
     1137
     1138test space-7.0.1.11 {check for tabs between multiple unit string with multiplication} {
     1139    list [catch {Rappture::Units::Search::for "300\tK\t*\tft"} msg] $msg
     1140} {0 Kft}
     1141
     1142test space-7.0.2.1 {check for newlines before value unit string} {
     1143    list [catch {Rappture::Units::Search::for "\n300K"} msg] $msg
     1144} {0 K}
     1145
     1146test space-7.0.2.2 {check for newlines after value unit string} {
     1147    list [catch {Rappture::Units::Search::for "300K\n"} msg] $msg
     1148} {0 K}
     1149
     1150test space-7.0.2.3 {check for newlines before and after value unit string} {
     1151    list [catch {Rappture::Units::Search::for "\n300K\n"} msg] $msg
     1152} {0 K}
     1153
     1154test space-7.0.2.4 {check for newlines between value and unit string} {
     1155    list [catch {Rappture::Units::Search::for "\n300\nK\n"} msg] $msg
     1156} {0 K}
     1157
     1158test space-7.0.2.5 {check for newlines between value and single unit string} {
     1159    list [catch {Rappture::Units::Search::for "300\nK"} msg] $msg
     1160} {0 K}
     1161
     1162test space-7.0.2.6 {check for newlines between value and multiple unit string} {
     1163    list [catch {Rappture::Units::Search::for "300\nKft"} msg] $msg
     1164} {0 Kft}
     1165
     1166test space-7.0.2.7 {check for newlines around and between value and multiple unit string} {
     1167    list [catch {Rappture::Units::Search::for "\n300\nKft\n"} msg] $msg
     1168} {0 Kft}
     1169
     1170test space-7.0.2.8 {check for newlines between multiple unit string} {
     1171    list [catch {Rappture::Units::Search::for "300\nK\nft"} msg] $msg
     1172} {0 Kft}
     1173
     1174test space-7.0.2.9 {check for newlines around and between multiple unit string} {
     1175    list [catch {Rappture::Units::Search::for "\n300\nK\nft\n"} msg] $msg
     1176} {0 Kft}
     1177
     1178test space-7.0.2.10 {check for newlines between multiple unit string with division} {
     1179    list [catch {Rappture::Units::Search::for "300\nK\n/\nft"} msg] $msg
     1180} {0 K/ft}
     1181
     1182test space-7.0.2.11 {check for newlines between multiple unit string with multiplication} {
     1183    list [catch {Rappture::Units::Search::for "300\nK\n*\nft"} msg] $msg
     1184} {0 Kft}
     1185
     1186# TODO:
     1187# add tests for space and tab, space and newline, tab and newline
     1188# add tests for bad characters &^%$#@!)(~`{}[]:;"'?><,.-_=+\ or |
     1189
    10501190::tcltest::cleanupTests
    10511191return
  • trunk/src/core/RpUnits.cc

    r1740 r1782  
    10251025    const RpUnits* prefix   = NULL;
    10261026
    1027 
    10281027    while ( !myInUnits.empty() ) {
    10291028
     
    10441043            // type = myInUnits[last] + type;
    10451044            // ignore * because we assume everything is multiplied together
     1045            myInUnits.erase(last);
     1046            continue;
     1047        }
     1048
     1049        // ignore whitespace characters
     1050        if (isspace(myInUnits[last])) {
     1051            // ignore whitespace characters, they represent multiplication
    10461052            myInUnits.erase(last);
    10471053            continue;
     
    32883294        retVal = 1;
    32893295    }
    3290     else {
    3291     }
    32923296
    32933297    outUnits = std::string(endptr);
Note: See TracChangeset for help on using the changeset viewer.