|
| 1 | +script "testInputLibrary" |
| 2 | +/* |
| 3 | +Copyright (C) 2015 LiveCode Ltd. |
| 4 | +
|
| 5 | +This file is part of LiveCode. |
| 6 | +
|
| 7 | +LiveCode is free software; you can redistribute it and/or modify it under |
| 8 | +the terms of the GNU General Public License v3 as published by the Free |
| 9 | +Software Foundation. |
| 10 | +
|
| 11 | +LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | +for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU General Public License |
| 17 | +along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 18 | + |
| 19 | +on revLoadLibrary |
| 20 | + if the target is not me then |
| 21 | + pass revLoadLibrary |
| 22 | + end if |
| 23 | + insert the script of me into back |
| 24 | +end revLoadLibrary |
| 25 | + |
| 26 | +local sTestStrings, sTestNumbers, sTestConversionStrings, sTestFilePaths, sArrayData |
| 27 | +local sInitialised |
| 28 | + |
| 29 | +function TestGetInputFilesFolder |
| 30 | + set the itemDelimiter to slash |
| 31 | + return item 1 to -2 of the filename of me & slash & "lcs-input-files" |
| 32 | +end TestGetInputFilesFolder |
| 33 | + |
| 34 | +private function getTestFile pTestFile |
| 35 | + local tContent, tFilePath |
| 36 | + |
| 37 | + put TestGetInputFilesFolder() & slash & pTestFile into tFilePath |
| 38 | + |
| 39 | + // test files are written without BOM |
| 40 | + open file tFilePath for "utf8" text read |
| 41 | + read from file tFilePath until EOF |
| 42 | + |
| 43 | + put it into tContent |
| 44 | + |
| 45 | + close file tFilePath |
| 46 | + return tContent |
| 47 | +end getTestFile |
| 48 | + |
| 49 | +on setUpValues |
| 50 | + if sInitialised then |
| 51 | + exit setUpValues |
| 52 | + end if |
| 53 | + |
| 54 | + put true into sInitialised |
| 55 | + |
| 56 | + //load in strings |
| 57 | + local tStrings |
| 58 | + put getTestFile("testStrings.txt") into tStrings |
| 59 | + put empty into sArrayData |
| 60 | + |
| 61 | + local tFirstLine |
| 62 | + put line 1 of tStrings into tFirstLine |
| 63 | + delete line 1 of tStrings |
| 64 | + |
| 65 | + repeat for each line tLine in tStrings |
| 66 | + local tType, tNumber |
| 67 | + put item 1 of tLine into tType |
| 68 | + put item 2 of tLine into tNumber |
| 69 | + |
| 70 | + put item 3 of tLine into sTestStrings[tType][tNumber][item 3 of tFirstLine] |
| 71 | + put item 4 of tLine into sTestStrings[tType][tNumber][item 4 of tFirstLine] |
| 72 | + put item 5 of tLine into sTestStrings[tType][tNumber][item 5 of tFirstLine] |
| 73 | + put item 6 of tLine into sTestStrings[tType][tNumber][item 6 of tFirstLine] |
| 74 | + end repeat |
| 75 | + |
| 76 | + |
| 77 | + //load in numbers |
| 78 | + local tNumbers |
| 79 | + put getTestFile("testNumbers.txt") into tNumbers |
| 80 | + |
| 81 | + repeat for each line tLine in tNumbers |
| 82 | + put item 2 of tLine into sTestNumbers[item 1 of tLine][1] |
| 83 | + put item 3 of tLine into sTestNumbers[item 1 of tLine][2] |
| 84 | + end repeat |
| 85 | + |
| 86 | + |
| 87 | + // Load in conversion strings |
| 88 | + local tConversionStrings |
| 89 | + put getTestFile("testConversionStrings.txt") into tConversionStrings |
| 90 | + |
| 91 | + repeat for each line tLine in tConversionStrings |
| 92 | + put item 2 of tLine into sTestConversionStrings[item 1 of tLine]["lowerCase"] |
| 93 | + put item 3 of tLine into sTestConversionStrings[item 1 of tLine]["upperCase"] |
| 94 | + put item 4 of tLine into sTestConversionStrings[item 1 of tLine]["lowerCaseNumber"] |
| 95 | + put item 5 of tLine into sTestConversionStrings[item 1 of tLine]["upperCaseNumber"] |
| 96 | + put item 6 of tLine into sTestConversionStrings[item 1 of tLine]["lowerCaseByte"] |
| 97 | + put item 7 of tLine into sTestConversionStrings[item 1 of tLine]["upperCaseByte"] |
| 98 | + end repeat |
| 99 | + |
| 100 | + |
| 101 | + // Load in file paths |
| 102 | + local tFilePaths |
| 103 | + put getTestFile("testFilePaths.txt") into tFilePaths |
| 104 | + |
| 105 | + repeat for each line tLine in tFilePaths |
| 106 | + put item 2 of tLine into sTestFilePaths[item 1 of tLine] |
| 107 | + end repeat |
| 108 | + |
| 109 | + |
| 110 | + // Load in array data |
| 111 | + local tArrayData |
| 112 | + put getTestFile("testArrayData.txt") into tArrayData |
| 113 | + |
| 114 | + repeat for each line tLine in tArrayData |
| 115 | + put item 2 to -1 of tLine into sArrayData[item 1 of tLine] |
| 116 | + end repeat |
| 117 | +end setUpValues |
| 118 | + |
| 119 | +function testString pType,pNumber, pValue |
| 120 | + setupValues |
| 121 | + if pValue is empty then put "string" into pValue |
| 122 | + put "String:" && pType, pNumber, pValue && sTestStrings[pType][pNumber][pValue]& return after url ("binfile:" & specialFolderPath("desktop") & "/log.txt") |
| 123 | + return sTestStrings[pType][pNumber][pValue] |
| 124 | +end testString |
| 125 | + |
| 126 | +function testNumber pType,pNumber |
| 127 | + setupValues |
| 128 | + return sTestNumbers[pType][pNumber] |
| 129 | +end testNumber |
| 130 | + |
| 131 | +function testConversionString pStringType, pConversionType |
| 132 | + setupValues |
| 133 | + return sTestConversionStrings[pStringType][pConversionType] |
| 134 | +end testConversionString |
| 135 | + |
| 136 | +function testFilePath pType |
| 137 | + setupValues |
| 138 | + return sTestFilePaths[pType] |
| 139 | +end testFilePath |
| 140 | + |
| 141 | +function testFolderList |
| 142 | + setupValues |
| 143 | + local tFileList |
| 144 | + repeat for each element tFile in sTestFilePaths |
| 145 | + put tFile & return after tFileList |
| 146 | + end repeat |
| 147 | + delete the last character of tFileList |
| 148 | + return tFileList |
| 149 | +end testFolderList |
| 150 | + |
| 151 | +function testFileList |
| 152 | + setupValues |
| 153 | + local tFileList |
| 154 | + repeat for each element tFile in sTestFilePaths |
| 155 | + put tFile & ".txt" & return after tFileList |
| 156 | + end repeat |
| 157 | + delete the last character of tFileList |
| 158 | + return tFileList |
| 159 | +end testFileList |
| 160 | + |
| 161 | +function testArrayData pKey |
| 162 | + setupValues |
| 163 | + return sArrayData[pKey] |
| 164 | +end testArrayData |
| 165 | + |
| 166 | +function TestGetInputFile pFilename |
| 167 | + return TestGetInputFilesFolder() & slash & pFilename |
| 168 | +end TestGetInputFile |
0 commit comments