Best JavaScript code snippet using testcafe
uber-document-functions.js
Source:uber-document-functions.js
1/**2 * 3 * @param {FileList} uberDocuments Uber売ãä¸ãPDFé
å4 * @returns {Array<UberPaymentData>} Uber売ãä¸ããã¼ã¿é
å5 */6async function uberDocumentsToDatas(uberDocuments) {7 const uberPaymentDatas = new Array();8 // ã¡ã¢ãªä½¿ç¨éãèæ
®ããåæããªããPDFã1ã¤ãã¤å¤æãã9 for(let uberDocument of uberDocuments) {10 const uberPaymentData = await uberDocumentToData(uberDocument);11 // æ¥ä»ä»¥å¤ã®å£²ãä¸ããªã©ã®æ
å ±ãåå¨ããã°è¿½å 12 if (!uberPaymentData.isZero()) {13 uberPaymentDatas.push(uberPaymentData);14 }15 }16 return uberPaymentDatas;17}18/**19 * Uber売ä¸PDFã®å¤æ20 * 21 * @param {File} uberDocument Uber売ãä¸ãã®PDFãã¡ã¤ã«22 * @returns Uber売ãä¸ããã¼ã¿23 */24 async function uberDocumentToData(uberDocument) {25 // PDFãã¡ã¤ã«èªã¿è¾¼ã¿26 // ï¼fileReader.onloadãPromiseãããªãã®ã§ãPromiseã«ããï¼27 const fileReader = new FileReader();28 const fileReadPromise = BrowserUtils.generatePromiseWithFileReader(fileReader);29 fileReader.readAsArrayBuffer(uberDocument);30 const arrayBuffer = await fileReadPromise;31 // PDFããArray<TextItem | TextMarkedContent>ãåå¾32 // åè33 // https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L68934 // https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L108235 // https://stackoverflow.com/a/6217341636 const pdfDocumentProxy = await pdfjsLib.getDocument(new Uint8Array(arrayBuffer)).promise;37 // 対象ã®ãã¼ã¸ããArray<TextItem | TextMarkedContent>ã«å¤æ38 const textItems = new Array();39 for (let i = UberDocumentConstants.UBER_SALE_FIRST_PAGE_INDEX; i <= pdfDocumentProxy.numPages && i <= UberDocumentConstants.UBER_SALE_PAGE_NUM; ++i) {40 const page = await pdfDocumentProxy.getPage(i);41 // TextContent https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L108142 const textContent = await page.getTextContent();43 ArrayUtils.pushArray(textItems, textContent.items);44 } 45 46 // ããã«UberPaymentDataã«å¤æ47 return textItemsToData(textItems);48}49/**50 * PDFã®ããã¹ãæ
å ±ãããã¼ã¿ç¨ã®ã¯ã©ã¹ã«å¤æ51 * @param {Array<TextItem | TextMarkedContent>} textItems 52 * @returns Uber売ãä¸ããã¼ã¿53 */54function textItemsToData(textItems) {55 const uberPaymentData = new UberPaymentData();56 // ååã®è§£æã¢ã¼ãï¼ãã£ã³ã»ã«ã®ã¨ãã«å
ã«æ»ãããï¼57 let previousParseMode;58 // å©ç¨ãã解æã¢ã¼ã59 const parseModes = [60 61 // é±ã®å§ã¾ãã®æ¥ä»ãæ¢ãã¦ä¿å62 new ParseMode(UberDocumentConstants.UBER_START_DATE_PATTERN, (result, index, source) => {63 uberPaymentData.startDate = SimpleDate.ofString(result[UberDocumentConstants.REGEXP_EXEC_PART_INDEX], UberDocumentConstants.UBER_DATE_SEPARATOR);64 }),65 // é±ã®çµããã®æ¥ä»ãæ¢ãã¦ä¿å66 new ParseMode(UberDocumentConstants.UBER_END_DATE_PATTERN, (result, index, source) => {67 uberPaymentData.endDate = SimpleDate.ofString(result[UberDocumentConstants.REGEXP_EXEC_PART_INDEX], UberDocumentConstants.UBER_DATE_SEPARATOR);68 }),69 // 売ãä¸ãã®ã©ãã«ãæ¢ãã次ã®æ°å¤ã売ãä¸ãã¨ã¿ãªã70 new ParseMode(UberDocumentConstants.UBER_SALE_LABEL_PATTERN, (result, index, source) => {71 parseModes.unshift(new IntegerParseMode(72 num => uberPaymentData.sale = num,73 true,74 // 売ãä¸ãã ãã¯ãã売ãä¸ãã®æç´°ããå
ã«èªã¿è¾¼ã¾ãã¦ãã¾ãå ´åãããããå
ã«æ»ã75 UberDocumentConstants.UBER_SALE_REVERT_PATTERN76 ));77 }),78 // ãµã¼ãã¹æï¼æ¯æææ°æï¼ã®ã©ãã«ãæ¢ãã次ã®æ°å¤ãæ¯æææ°æã¨ã¿ãªã79 new ParseMode(UberDocumentConstants.UBER_FEE_LABEL_PATTERN, (result, index, source) => {80 parseModes.unshift(new IntegerParseMode(num => uberPaymentData.fee = num, true));81 }),82 // éè¡å£åº§ã¸ã®æ¯ãè¾¼ã¿ã®ã©ãã«ãæ¢ã83 new ParseMode(UberDocumentConstants.UBER_DEPOSIT_LABEL_PATTERN, (result, index, source) => {84 // æ¯è¾¼å¹´ã¯é±ã®å§ã¾ãã®æ¥ä»ï¼ä¾ï¼2021/05/03ï¼ããåå¾85 uberPaymentData.depositDate = new SimpleDate();86 if (uberPaymentData.startDate) {87 uberPaymentData.depositDate.year = uberPaymentData.startDate.year;88 }89 // ãªãå ´åã¯ãªãã¯ãã ããããããããç¶æ³ãçºçããå ´åã¯ãä¸å¿åå¹´ãè¨å®90 else {91 uberPaymentData.depositDate.year = UberDocumentConstants.TODAY.getFullYear();92 }93 // ã©ãã«ããåã«æ¯è¾¼æ¥ä»ãæ¸ãã¦ãããããåãæ¢ãã¦è¨å®94 // ä¾ï¼5æ3æ¥(æ) 4:01 ã«éè¡å£åº§ã«æ¯ãè¾¼ã¾ãã¾ãã95 // æ±ãããä»ã®æ段ãæãã¤ããªã96 // ( ã®ä½ç½®ã¾ã§æ»ã97 do {98 --index;99 } while(source[index].str != "(");100 // 次ã®æ°å¤ãæ¥101 let regExpExecArray;102 do {103 --index;104 regExpExecArray = UberDocumentConstants.UBER_INTEGER_PATTERN.exec(source[index].str);105 } while(regExpExecArray == null);106 uberPaymentData.depositDate.day = regExpExecArray[UberDocumentConstants.REGEXP_EXEC_RESULT_INDEX];107 // 次ã®æ°å¤ãæ108 do {109 --index;110 regExpExecArray = UberDocumentConstants.UBER_INTEGER_PATTERN.exec(source[index].str);111 } while(regExpExecArray == null);112 uberPaymentData.depositDate.month = regExpExecArray[UberDocumentConstants.REGEXP_EXEC_RESULT_INDEX];113 // 次ã®æ°å¤ãæ¯ãè¾¼ã¾ããéé¡ã¨ã¿ãªã114 parseModes.unshift(new IntegerParseMode(num => uberPaymentData.deposit = num, true));115 }),116 // åãåã£ãç¾éã®ã©ãã«ãæ¢ãã次ã®æ°å¤ãæ¯ãè¾¼ã¾ããéé¡ã¨ã¿ãªã117 new ParseMode(UberDocumentConstants.UBER_CASH_LABEL_PATTERN, (result, index, source) => {118 parseModes.unshift(new IntegerParseMode(num => uberPaymentData.cash = num, true));119 }),120 // è¿éã¨çµè²»ã®ã©ãã«ãæ¢ãã次ã®æ°å¤ãæ¯ãè¾¼ã¾ããéé¡ã¨ã¿ãªã121 new ParseMode(UberDocumentConstants.UBER_REPAYMENT_LABEL_PATTERN, (result, index, source) => {122 parseModes.unshift(primalParseMode = new IntegerParseMode(num => uberPaymentData.repayment = num, true));123 }),124 ];125 // ããã¹ãã1ã¤ãã¤è§£æ126 for(let i = 0; i < textItems.length; ++i) {127 const textItem = textItems[i];128 if (!textItem || !textItem.str) {129 continue;130 }131 // ä»ã®è§£æã¢ã¼ãå®è¡ãçµäºããããã®ã¢ã¼ããæ¶ã132 for (const parseMode of parseModes) {133 if (parseMode.actionIfExecutable(textItem.str, i, textItems)) {134 ArrayUtils.delete(parseModes, parseMode);135 previousParseMode = parseMode;136 // åå¾ããæ
å ±ããªããªã£ããè¿ã137 if (parseModes.length <= 0 && !primalParseMode) {138 return uberPaymentData;139 }140 break;141 }142 // å
ã«æ»ãæ¡ä»¶ã«ä¸è´ããå ´åã¯å
ã«æ»ã143 if (parseMode.revertPattern && parseMode.revertPattern.test(textItem.str) && previousParseMode) {144 ArrayUtils.delete(parseModes, parseMode);145 parseModes.unshift(previousParseMode);146 previousParseMode = null;147 break;148 }149 150 // åªå
解æã¢ã¼ãã®å ´åã¯æ¬¡ã®ããã¹ãã¸151 if (parseMode.primalFlag) {152 break;153 }154 }155 }156 return uberPaymentData;...
13.js
Source:13.js
...80 op = String(op).padStart(2, '0');81 // Input82 if (effectiveOp(op) === '03') {83 let targetIdx = state.mem[state.pointer + 1];84 if (parseModes(op)[0] == '2') {85 targetIdx += state.rbase;86 }87 const value = await input();88 return {89 ...state,90 pointer: state.pointer + 2,91 mem: set(state, targetIdx, value).mem,92 };93 } else if (effectiveOp(op) === '01') { // Sum94 const args = readArgs(state, 2, parseModes(op));95 let targetIdx = state.mem[state.pointer + 3];96 if(parseModes(op)[2] == '2') {97 targetIdx += state.rbase;98 }99 return {100 ...state,101 pointer: state.pointer + 4,102 mem: set(state, targetIdx, R.sum(args)).mem,103 };104 } else if (effectiveOp(op) === '02') { // Product105 const args = readArgs(state, 2, parseModes(op));106 let targetIdx = state.mem[state.pointer + 3];107 if(parseModes(op)[2] == '2') {108 targetIdx += state.rbase;109 }110 return {111 ...state,112 pointer: state.pointer + 4,113 mem: set(state, targetIdx, R.product(args)).mem,114 };115 } else if (effectiveOp(op) === '99') { // Exit116 console.log("Finished");117 return {118 ...state,119 pointer: -1120 };121 } else if (effectiveOp(op) === '04') { // Output122 const args = readArgs(state, 1, parseModes(op));123 output(args[0]);124 return {125 ...state,126 pointer: state.pointer + 2,127 };128 } else if (effectiveOp(op) === '05') { // Jump If True129 const args = readArgs(state, 2, parseModes(op));130 if (args[0] !== 0) {131 return {132 ...state,133 pointer: args[1]134 };135 } else {136 return {137 ...state,138 pointer: state.pointer + 3,139 };140 }141 } else if (effectiveOp(op) === '06') { // Jump if False142 const args = readArgs(state, 2, parseModes(op));143 if (args[0] === 0) {144 return {145 ...state,146 pointer: args[1],147 };148 } else {149 return {150 ...state,151 pointer: state.pointer + 3,152 };153 }154 } else if (effectiveOp(op) === '07') { // less than155 const args = readArgs(state, 2, parseModes(op));156 let targetIdx = state.mem[state.pointer + 3];157 if(parseModes(op)[2] == '2') {158 targetIdx += state.rbase;159 }160 if (args[0] < args[1]) {161 return {162 ...state,163 pointer: state.pointer + 4,164 mem: set(state, targetIdx, 1).mem,165 };166 } else {167 return {168 ...state,169 pointer: state.pointer + 4,170 mem: set(state, targetIdx, 0).mem,171 };172 }173 } else if (effectiveOp(op) === '08') { // Equals174 const args = readArgs(state, 2, parseModes(op));175 let targetIdx = state.mem[state.pointer + 3];176 // console.log("args: ", args);177 if(parseModes(op)[2] == '2') {178 targetIdx += state.rbase;179 }180 if (args[0] === args[1]) {181 return {182 ...state,183 pointer: state.pointer + 4,184 mem: set(state, targetIdx, 1).mem,185 };186 } else {187 return {188 ...state,189 pointer: state.pointer + 4,190 mem: set(state, targetIdx, 0).mem,191 };192 }193 } else if (effectiveOp(op) === '09') { // Adjust Rbase194 return op09(state, op);195 }196}197const op09 = (state, op) => {198 const args = readArgs(state, 1, parseModes(op));199 return {200 ...state,201 pointer: state.pointer + 2,202 rbase: state.rbase + args[0],203 }204}205const runProgram = async (program, input, output) => {206 let state = {207 pointer: 0,208 mem: program,209 rbase: 0,210 backingMem: {},211 }212 while (state.pointer !== -1) {...
11.js
Source:11.js
...50 op = String(op).padStart(2, '0');51 // Input52 if (effectiveOp(op) === '03') {53 let targetIdx = state.mem[state.pointer + 1];54 if (parseModes(op)[0] == '2') {55 targetIdx += state.rbase;56 }57 const value = input();58 return {59 ...state,60 pointer: state.pointer + 2,61 mem: set(state, targetIdx, value).mem,62 };63 } else if (effectiveOp(op) === '01') { // Sum64 const args = readArgs(state, 2, parseModes(op));65 let targetIdx = state.mem[state.pointer + 3];66 if(parseModes(op)[2] == '2') {67 targetIdx += state.rbase;68 }69 return {70 ...state,71 pointer: state.pointer + 4,72 mem: set(state, targetIdx, R.sum(args)).mem,73 };74 } else if (effectiveOp(op) === '02') { // Product75 const args = readArgs(state, 2, parseModes(op));76 let targetIdx = state.mem[state.pointer + 3];77 if(parseModes(op)[2] == '2') {78 targetIdx += state.rbase;79 }80 return {81 ...state,82 pointer: state.pointer + 4,83 mem: set(state, targetIdx, R.product(args)).mem,84 };85 } else if (effectiveOp(op) === '99') { // Exit86 console.log("Finished");87 return {88 ...state,89 pointer: -190 };91 } else if (effectiveOp(op) === '04') { // Output92 const args = readArgs(state, 1, parseModes(op));93 output(args[0]);94 return {95 ...state,96 pointer: state.pointer + 2,97 };98 } else if (effectiveOp(op) === '05') { // Jump If True99 const args = readArgs(state, 2, parseModes(op));100 if (args[0] !== 0) {101 return {102 ...state,103 pointer: args[1]104 };105 } else {106 return {107 ...state,108 pointer: state.pointer + 3,109 };110 }111 } else if (effectiveOp(op) === '06') { // Jump if False112 const args = readArgs(state, 2, parseModes(op));113 if (args[0] === 0) {114 return {115 ...state,116 pointer: args[1],117 };118 } else {119 return {120 ...state,121 pointer: state.pointer + 3,122 };123 }124 } else if (effectiveOp(op) === '07') { // less than125 const args = readArgs(state, 2, parseModes(op));126 let targetIdx = state.mem[state.pointer + 3];127 if(parseModes(op)[2] == '2') {128 targetIdx += state.rbase;129 }130 if (args[0] < args[1]) {131 return {132 ...state,133 pointer: state.pointer + 4,134 mem: set(state, targetIdx, 1).mem,135 };136 } else {137 return {138 ...state,139 pointer: state.pointer + 4,140 mem: set(state, targetIdx, 0).mem,141 };142 }143 } else if (effectiveOp(op) === '08') { // Equals144 const args = readArgs(state, 2, parseModes(op));145 let targetIdx = state.mem[state.pointer + 3];146 // console.log("args: ", args);147 if(parseModes(op)[2] == '2') {148 targetIdx += state.rbase;149 }150 if (args[0] === args[1]) {151 return {152 ...state,153 pointer: state.pointer + 4,154 mem: set(state, targetIdx, 1).mem,155 };156 } else {157 return {158 ...state,159 pointer: state.pointer + 4,160 mem: set(state, targetIdx, 0).mem,161 };162 }163 } else if (effectiveOp(op) === '09') { // Adjust Rbase164 return op09(state, op);165 }166}167const op09 = (state, op) => {168 const args = readArgs(state, 1, parseModes(op));169 return {170 ...state,171 pointer: state.pointer + 2,172 rbase: state.rbase + args[0],173 }174}175const runProgram = (program) => {176 let state = {177 pointer: 0,178 mem: program,179 rbase: 0,180 backingMem: {},181 pos: [0, 0],182 direction: 1,...
7.js
Source:7.js
...35 pointer: state.pointer + 2,36 mem: R.update(targetIdx, value, state.mem),37 };38 } else if (effectiveOp(op) === '01') {39 const args = readArgs(state, 2, parseModes(op));40 // console.log("args: ", args);41 // console.log("setting index:", state.mem[state.pointer+3], " to", R.sum(args))42 return {43 pointer: state.pointer + 4,44 mem: R.update(state.mem[state.pointer + 3], R.sum(args), state.mem),45 };46 } else if (effectiveOp(op) === '02') {47 const args = readArgs(state, 2, parseModes(op));48 return {49 pointer: state.pointer + 4,50 mem: R.update(state.mem[state.pointer + 3], R.product(args), state.mem),51 };52 } else if (effectiveOp(op) === '99') {53 // console.log("Finished");54 return {55 ...state,56 pointer: -157 };58 } else if (effectiveOp(op) === '04') {59 output(state.mem[state.mem[state.pointer + 1]]);60 return {61 ...state,62 pointer: state.pointer + 2,63 };64 } else if (effectiveOp(op) === '05') {65 const args = readArgs(state, 2, parseModes(op));66 if (args[0] !== 0) {67 return {68 ...state,69 pointer: args[1]70 };71 } else {72 return {73 ...state,74 pointer: state.pointer + 3,75 };76 }77 } else if (effectiveOp(op) === '06') {78 const args = readArgs(state, 2, parseModes(op));79 if (args[0] === 0) {80 return {81 ...state,82 pointer: args[1],83 };84 } else {85 return {86 ...state,87 pointer: state.pointer + 3,88 };89 }90 } else if (effectiveOp(op) === '07') {91 const args = readArgs(state, 2, parseModes(op));92 if (args[0] < args[1]) {93 return {94 pointer: state.pointer + 4,95 mem: R.update(state.mem[state.pointer + 3], 1, state.mem),96 };97 } else {98 return {99 pointer: state.pointer + 4,100 mem: R.update(state.mem[state.pointer + 3], 0, state.mem),101 };102 }103 } else if (effectiveOp(op) === '08') {104 const args = readArgs(state, 2, parseModes(op));105 if (args[0] === args[1]) {106 return {107 pointer: state.pointer + 4,108 mem: R.update(state.mem[state.pointer + 3], 1, state.mem),109 };110 } else {111 return {112 pointer: state.pointer + 4,113 mem: R.update(state.mem[state.pointer + 3], 0, state.mem),114 };115 }116 }117}118const runProgram = (program, input, output) => {...
17.js
Source:17.js
...50 op = String(op).padStart(2, '0');51 // Input52 if (effectiveOp(op) === '03') {53 let targetIdx = state.mem[state.pointer + 1];54 if (parseModes(op)[0] == '2') {55 targetIdx += state.rbase;56 }57 const value = await input();58 return {59 ...state,60 pointer: state.pointer + 2,61 mem: set(state, targetIdx, value).mem,62 };63 } else if (effectiveOp(op) === '01') { // Sum64 const args = readArgs(state, 2, parseModes(op));65 let targetIdx = state.mem[state.pointer + 3];66 if(parseModes(op)[2] == '2') {67 targetIdx += state.rbase;68 }69 return {70 ...state,71 pointer: state.pointer + 4,72 mem: set(state, targetIdx, R.sum(args)).mem,73 };74 } else if (effectiveOp(op) === '02') { // Product75 const args = readArgs(state, 2, parseModes(op));76 let targetIdx = state.mem[state.pointer + 3];77 if(parseModes(op)[2] == '2') {78 targetIdx += state.rbase;79 }80 return {81 ...state,82 pointer: state.pointer + 4,83 mem: set(state, targetIdx, R.product(args)).mem,84 };85 } else if (effectiveOp(op) === '99') { // Exit86 console.log("Finished");87 return {88 ...state,89 pointer: -190 };91 } else if (effectiveOp(op) === '04') { // Output92 const args = readArgs(state, 1, parseModes(op));93 output(args[0]);94 return {95 ...state,96 pointer: state.pointer + 2,97 };98 } else if (effectiveOp(op) === '05') { // Jump If True99 const args = readArgs(state, 2, parseModes(op));100 if (args[0] !== 0) {101 return {102 ...state,103 pointer: args[1]104 };105 } else {106 return {107 ...state,108 pointer: state.pointer + 3,109 };110 }111 } else if (effectiveOp(op) === '06') { // Jump if False112 const args = readArgs(state, 2, parseModes(op));113 if (args[0] === 0) {114 return {115 ...state,116 pointer: args[1],117 };118 } else {119 return {120 ...state,121 pointer: state.pointer + 3,122 };123 }124 } else if (effectiveOp(op) === '07') { // less than125 const args = readArgs(state, 2, parseModes(op));126 let targetIdx = state.mem[state.pointer + 3];127 if(parseModes(op)[2] == '2') {128 targetIdx += state.rbase;129 }130 if (args[0] < args[1]) {131 return {132 ...state,133 pointer: state.pointer + 4,134 mem: set(state, targetIdx, 1).mem,135 };136 } else {137 return {138 ...state,139 pointer: state.pointer + 4,140 mem: set(state, targetIdx, 0).mem,141 };142 }143 } else if (effectiveOp(op) === '08') { // Equals144 const args = readArgs(state, 2, parseModes(op));145 let targetIdx = state.mem[state.pointer + 3];146 // console.log("args: ", args);147 if(parseModes(op)[2] == '2') {148 targetIdx += state.rbase;149 }150 if (args[0] === args[1]) {151 return {152 ...state,153 pointer: state.pointer + 4,154 mem: set(state, targetIdx, 1).mem,155 };156 } else {157 return {158 ...state,159 pointer: state.pointer + 4,160 mem: set(state, targetIdx, 0).mem,161 };162 }163 } else if (effectiveOp(op) === '09') { // Adjust Rbase164 return op09(state, op);165 }166}167const op09 = (state, op) => {168 const args = readArgs(state, 1, parseModes(op));169 return {170 ...state,171 pointer: state.pointer + 2,172 rbase: state.rbase + args[0],173 }174}175const runProgram = async (program, input, output) => {176 let state = {177 pointer: 0,178 mem: program,179 rbase: 0,180 backingMem: {},181 }182 while (state.pointer !== -1) {...
9.js
Source:9.js
...50 op = String(op).padStart(2, '0');51 // Input52 if (effectiveOp(op) === '03') {53 let targetIdx = state.mem[state.pointer + 1];54 if (parseModes(op)[0] == '2') {55 targetIdx += state.rbase;56 }57 const value = input();58 return {59 ...state,60 pointer: state.pointer + 2,61 mem: set(state, targetIdx, value).mem,62 };63 } else if (effectiveOp(op) === '01') { // Sum64 const args = readArgs(state, 2, parseModes(op));65 let targetIdx = state.mem[state.pointer + 3];66 if(parseModes(op)[2] == '2') {67 targetIdx += state.rbase;68 }69 return {70 ...state,71 pointer: state.pointer + 4,72 mem: set(state, targetIdx, R.sum(args)).mem,73 };74 } else if (effectiveOp(op) === '02') { // Product75 const args = readArgs(state, 2, parseModes(op));76 let targetIdx = state.mem[state.pointer + 3];77 if(parseModes(op)[2] == '2') {78 targetIdx += state.rbase;79 }80 return {81 ...state,82 pointer: state.pointer + 4,83 mem: set(state, targetIdx, R.product(args)).mem,84 };85 } else if (effectiveOp(op) === '99') { // Exit86 console.log("Finished");87 return {88 ...state,89 pointer: -190 };91 } else if (effectiveOp(op) === '04') { // Output92 const args = readArgs(state, 1, parseModes(op));93 output(args[0]);94 return {95 ...state,96 pointer: state.pointer + 2,97 };98 } else if (effectiveOp(op) === '05') { // Jump If True99 const args = readArgs(state, 2, parseModes(op));100 if (args[0] !== 0) {101 return {102 ...state,103 pointer: args[1]104 };105 } else {106 return {107 ...state,108 pointer: state.pointer + 3,109 };110 }111 } else if (effectiveOp(op) === '06') { // Jump if False112 const args = readArgs(state, 2, parseModes(op));113 if (args[0] === 0) {114 return {115 ...state,116 pointer: args[1],117 };118 } else {119 return {120 ...state,121 pointer: state.pointer + 3,122 };123 }124 } else if (effectiveOp(op) === '07') { // less than125 const args = readArgs(state, 2, parseModes(op));126 let targetIdx = state.mem[state.pointer + 3];127 if(parseModes(op)[2] == '2') {128 targetIdx += state.rbase;129 }130 if (args[0] < args[1]) {131 return {132 ...state,133 pointer: state.pointer + 4,134 mem: set(state, targetIdx, 1).mem,135 };136 } else {137 return {138 ...state,139 pointer: state.pointer + 4,140 mem: set(state, targetIdx, 0).mem,141 };142 }143 } else if (effectiveOp(op) === '08') { // Equals144 const args = readArgs(state, 2, parseModes(op));145 let targetIdx = state.mem[state.pointer + 3];146 // console.log("args: ", args);147 if(parseModes(op)[2] == '2') {148 targetIdx += state.rbase;149 }150 if (args[0] === args[1]) {151 return {152 ...state,153 pointer: state.pointer + 4,154 mem: set(state, targetIdx, 1).mem,155 };156 } else {157 return {158 ...state,159 pointer: state.pointer + 4,160 mem: set(state, targetIdx, 0).mem,161 };162 }163 } else if (effectiveOp(op) === '09') { // Adjust Rbase164 return op09(state, op);165 }166}167const op09 = (state, op) => {168 const args = readArgs(state, 1, parseModes(op));169 return {170 ...state,171 pointer: state.pointer + 2,172 rbase: state.rbase + args[0],173 }174}175const runProgram = (program, input, output) => {176 let state = {177 pointer: 0,178 mem: program,179 rbase: 0,180 backingMem: {},181 }182 while (state.pointer !== -1) {...
2.2.sneak.js
Source:2.2.sneak.js
...35 pointer: state.pointer + 2,36 mem: R.update(targetIdx, value, state.mem),37 };38 } else if (effectiveOp(op) === '01') {39 const args = readArgs(state, 2, parseModes(op));40 console.log(args);41 return {42 pointer: state.pointer + 4,43 // mem: R.update(state.mem[state.pointer + 3], R.sum(args), state.mem),44 mem: R.update(state.mem[state.pointer + 3],45 !isNaN(args[0]) && !isNaN(args[1]) ? Number(args[0]) + Number(args[1]) : '(' + args[0] + ' + ' + args[1] + ')',46 state.mem),47 };48 } else if (effectiveOp(op) === '02') {49 const args = readArgs(state, 2, parseModes(op));50 console.log(args);51 return {52 pointer: state.pointer + 4,53 // mem: R.update(state.mem[state.pointer + 3], R.product(args), state.mem),54 mem: R.update(state.mem[state.pointer + 3],55 !isNaN(args[0]) && !isNaN(args[1]) ? Number(args[0]) * Number(args[1]) : '(' + args[0] + ')' + '(' + args[1] + ')',56 state.mem),57 };58 } else if (effectiveOp(op) === '99') {59 console.log("Finished");60 return {61 ...state,62 pointer: -163 };64 } else if (effectiveOp(op) === '04') {65 output(state.mem[state.mem[state.pointer + 1]]);66 return {67 ...state,68 pointer: state.pointer + 2,69 };70 } else if (effectiveOp(op) === '05') {71 const args = readArgs(state, 2, parseModes(op));72 if (args[0] !== 0) {73 return {74 ...state,75 pointer: args[1]76 };77 } else {78 return {79 ...state,80 pointer: state.pointer + 3,81 };82 }83 } else if (effectiveOp(op) === '06') {84 const args = readArgs(state, 2, parseModes(op));85 if (args[0] === 0) {86 return {87 ...state,88 pointer: args[1],89 };90 } else {91 return {92 ...state,93 pointer: state.pointer + 3,94 };95 }96 } else if (effectiveOp(op) === '07') {97 const args = readArgs(state, 2, parseModes(op));98 if (args[0] < args[1]) {99 return {100 pointer: state.pointer + 4,101 mem: R.update(state.mem[state.pointer + 3], 1, state.mem),102 };103 } else {104 return {105 pointer: state.pointer + 4,106 mem: R.update(state.mem[state.pointer + 3], 0, state.mem),107 };108 }109 } else if (effectiveOp(op) === '08') {110 const args = readArgs(state, 2, parseModes(op));111 if (args[0] === args[1]) {112 return {113 pointer: state.pointer + 4,114 mem: R.update(state.mem[state.pointer + 3], 1, state.mem),115 };116 } else {117 return {118 pointer: state.pointer + 4,119 mem: R.update(state.mem[state.pointer + 3], 0, state.mem),120 };121 }122 }123}124const runProgram = (program, input, output) => {...
5.js
Source:5.js
...33 const value = getInput();34 state.mem[targetIdx] = value;35 state.pointer = state.pointer + 2;36 } else if (effectiveOp(op) === '01') {37 const args = readArgs(state, 2, parseModes(op));38 state.mem[state.mem[state.pointer + 3]] = R.sum(args);39 state.pointer = state.pointer + 4;40 } else if (effectiveOp(op) === '02') {41 const args = readArgs(state, 2, parseModes(op));42 state.mem[state.mem[state.pointer + 3]] = R.product(args);43 state.pointer = state.pointer + 4;44 } else if (effectiveOp(op) === '99') {45 console.log("Finished");46 state.pointer = -1;47 } else if (effectiveOp(op) === '04') {48 output(state.mem[state.mem[state.pointer + 1]]);49 state.pointer = state.pointer + 2;50 } else if (effectiveOp(op) === '05') {51 const args = readArgs(state, 2, parseModes(op));52 if (args[0] !== 0) {53 state.pointer = args[1];54 } else {55 state.pointer = state.pointer + 3;56 }57 } else if (effectiveOp(op) === '06') {58 const args = readArgs(state, 2, parseModes(op));59 if (args[0] === 0) {60 state.pointer = args[1];61 } else {62 state.pointer = state.pointer + 3;63 }64 } else if (effectiveOp(op) === '07') {65 const args = readArgs(state, 2, parseModes(op));66 if (args[0] < args[1]) {67 state.mem[state.mem[state.pointer + 3]] = 1;68 } else {69 state.mem[state.mem[state.pointer + 3]] = 0;70 }71 state.pointer = state.pointer + 4;72 } else if (effectiveOp(op) === '08') {73 const args = readArgs(state, 2, parseModes(op));74 if (args[0] === args[1]) {75 state.mem[state.mem[state.pointer + 3]] = 1;76 } else {77 state.mem[state.mem[state.pointer + 3]] = 0;78 }79 state.pointer = state.pointer + 4;80 }81}82const runProgram = (program) => {83 const state = {84 pointer: 0,85 mem: program,86 }87 while (state.pointer !== -1) {...
Using AI Code Generation
1import { parseModes } from 'testcafe';2import { Selector } from 'testcafe';3test('My first test', async t => {4 .typeText('#developer-name', 'John Smith')5 .click('#submit-button');6 const articleHeader = await Selector('.result-content').find('h1');7 let headerText = await articleHeader.innerText;8});9const modes = parseModes(process.argv.slice(2));10console.log(modes);11const modes = parseModes(process.argv.slice(2));12console.log(modes);13const modes = parseModes(process.argv.slice(2));14console.log(modes);15const modes = parseModes(process.argv.slice(2));16console.log(modes);17const modes = parseModes(process.argv.slice(2));18console.log(modes);19const modes = parseModes(process.argv.slice(2));20console.log(modes);
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3 const developerNameInput = Selector('#developer-name');4 .typeText(developerNameInput, 'Peter')5 .expect(developerNameInput.value).eql('Peter');6});7import { Selector } from 'testcafe';8test('My Test', async t => {9 const developerNameInput = Selector('#developer-name');10 .typeText(developerNameInput, 'Peter')11 .expect(developerNameInput.value).eql('Peter');12});13import { Selector } from 'testcafe';14test('My Test', async t => {15 const developerNameInput = Selector('#developer-name');16 .typeText(developerNameInput, 'Peter')17 .expect(developerNameInput.value).eql('Peter');18});19import { Selector } from 'testcafe';20test('My Test', async t => {21 const developerNameInput = Selector('#developer-name');22 .typeText(developerNameInput, 'Peter')23 .expect(developerNameInput.value).eql('Peter');24});25import { Selector } from 'testcafe';26test('My Test', async t => {27 const developerNameInput = Selector('#developer-name');28 .typeText(developerNameInput, 'Peter')29 .expect(developerNameInput.value).eql('Peter');30});31import { Selector
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3});4export default class Test {5 constructor() {6 this.nameInput = Selector('#developer-name');7 this.submitButton = Selector('#submit-button');8 }9}10import { Selector } from 'testcafe';11import Test from './test';12const test = new Test();13test('My first test', async t => {14});15export default class Test {16 constructor() {17 this.nameInput = Selector('#developer-name');18 this.submitButton = Selector('#submit-button');19 }20}21{22 "compileOpts": {23 }24}
Using AI Code Generation
1import { parseModes } from 'testcafe';2 .meta('skip', 'true')3 ('My test', async t => {4 });5const modes = parseModes(process.argv);6if (modes.skip) {7 fixture.skip('My fixture', () => {});8}9if (modes.only) {10 fixture.only('My fixture', () => {});11}12if (modes.skip) {13 test.skip('My test', () => {});14}15if (modes.only) {16 test.only('My test', () => {});17}18if (modes.debug) {19 ('My test', () => {});20}21if (modes.speed) {22 .speed(modes.speed)23 ('My test', () => {});24}25if (modes.debug) {26 .before(() => {})27 .after(() => {})28 .beforeEach(() => {})29 .afterEach(() => {})30 ('My test', () => {});31}32if (modes.skipJsErrors) {33 ('My test', () => {});34}35if (modes.skipUncaughtErrors) {36 ('My test', () =>
Using AI Code Generation
1import { Selector } from 'testcafe';2const testControllerHolder = require('./testControllerHolder');3test('My first test', async t => {4 .typeText('#developer-name', 'John Smith')5 .click('#submit-button');6 const articleHeader = await Selector('.result-content').find('h1');7 let headerText = await articleHeader.innerText;8 let headerHTML = await articleHeader.innerHTML;9 console.log('Header text: ' + headerText);10 console.log('Header HTML: ' + headerHTML);11});12const createTestCafe = require('testcafe');13let testcafe = null;14createTestCafe('localhost', 1337, 1338)15 .then(tc => {16 testcafe = tc;17 const runner = testcafe.createRunner();18 .src('./test.js')19 .browsers('chrome')20 .run();21 })22 .then(failedCount => {23 console.log('Tests failed: ' + failedCount);24 testcafe.close();25 });26const createTestCafe = require('testcafe');27let testcafe = null;28createTestCafe('localhost', 1337, 1338)29 .then(tc => {30 testcafe = tc;31 const runner = testcafe.createRunner();32 .src('./test.js')33 .browsers('chrome')34 .run();35 })36 .then(failedCount => {37 console.log('Tests failed: ' + failedCount);38 testcafe.close();39 });40const createTestCafe = require('testcafe');41let testcafe = null;42createTestCafe('localhost', 1337, 1338)43 .then(tc => {44 testcafe = tc;45 const runner = testcafe.createRunner();46 .src('./test.js')47 .browsers('chrome')48 .run();49 })50 .then(failedCount
Using AI Code Generation
1import { Selector, t } from 'testcafe';2test('My first test', async t => {3 const developerNameInput = Selector('#developer-name');4 .typeText(developerNameInput, 'Peter')5 .click('#submit-button')6 .expect(Selector('#article-header').innerText).eql('Thank you, Peter!');7});
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const getParseModes = ClientFunction(() => {3 return window.parseModes;4});5test('My first test', async t => {6 const parseModes = await getParseModes();7 console.log(parseModes);8});9import { ClientFunction } from 'testcafe';10const getParseModes = ClientFunction(() => {11 return window.parseModes;12});13test('My first test', async t => {14 const parseModes = await getParseModes();15 console.log(parseModes);16});17import { ClientFunction } from 'testcafe';18const getParseModes = ClientFunction(() => {19 return window.parseModes;20});21test('My first test', async t => {22 const parseModes = await getParseModes();23 console.log(parseModes);24});25import { ClientFunction } from 'testcafe';26const getParseModes = ClientFunction(() => {27 return window.parseModes;28});29test('My first test', async t => {30 const parseModes = await getParseModes();31 console.log(parseModes);32});33import { ClientFunction } from 'testcafe';34const getParseModes = ClientFunction(() => {35 return window.parseModes;36});37test('My first test', async t => {38 const parseModes = await getParseModes();39 console.log(parseModes);40});41import { ClientFunction } from 'testcafe';
Using AI Code Generation
1import { parseModes } from 'testcafe';2test('My first test', async t => {3 const modes = parseModes('desktop:chrome;mobile:iphone;tablet:ipad');4 .typeText('#developer-name', 'John Smith')5 .click('#submit-button');6});7const modes = parseModes('desktop:chrome;mobile:iphone;tablet:ipad');8 .typeText('#developer-name', 'John Smith')9 .click('#submit-button');
Using AI Code Generation
1import { parseModes } from 'testcafe';2const mode = parseModes('testcafe');3const mode = parseModes('testcafe', 'testcafe');4const mode = parseModes('testcafe', 'testcafe', 'testcafe');5const mode = parseModes('testcafe', 'testcafe', 'testcafe', 'testcafe');6const mode = parseModes('testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe');7const mode = parseModes('testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe');8const mode = parseModes('testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe', 'testcafe');
Using AI Code Generation
1const parseModes = require('testcafe/lib/utils/parse-modes');2const mode = parseModes('chrome --headless --no-sandbox');3console.log(mode);4{ browser: 'chrome',5 isMultiBrowser: false }6const getBrowserInfo = require('testcafe/lib/utils/browser-info');7const browserInfo = getBrowserInfo('chrome --headless --no-sandbox');8console.log(browserInfo);9{ alias: 'chrome',10 isMultiBrowser: false }11const parseBrowserList = require('testcafe/lib/utils/browser-list');12const browserList = parseBrowserList('chrome:headless --no-sandbox');13console.log(browserList);14[ { alias: 'chrome',15 isMultiBrowser: false } ]16const getBrowserList = require('testcafe/lib/utils/browser-list');17const browserList = getBrowserList('chrome:headless --no-sandbox');18console.log(browserList);19[ { alias: 'chrome',20 isMultiBrowser: false } ]21const getBrowserId = require('testcafe/lib/utils/browser-id');22const browserId = getBrowserId('chrome');23console.log(browserId);24const getBrowserName = require('testcafe/lib/utils/browser-name');25const browserName = getBrowserName('chrome');26console.log(browserName);27const parseUserAgent = require('testcafe/lib/utils/parse-user-agent');28const userAgent = parseUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!