|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <title>Tests!</title> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <script type="text/javascript" src="../fikascript.js"></script> |
| 6 | + <script type="text/javascript" src="../fikascript.browser.js"></script> |
| 7 | + <style type="text/css"> |
| 8 | + .diff { |
| 9 | + color: red; |
| 10 | + } |
| 11 | + |
| 12 | + #codeDiff { |
| 13 | + display: none; |
| 14 | + } |
| 15 | + |
| 16 | + .success { |
| 17 | + color: green; |
| 18 | + } |
| 19 | + |
| 20 | + .fail { |
| 21 | + color: red; |
| 22 | + } |
| 23 | + </style> |
| 24 | + <script> |
| 25 | + |
| 26 | + if (window.addEventListener) { |
| 27 | + window.addEventListener('DOMContentLoaded', runTests, false); |
| 28 | + } else { |
| 29 | + window.attachEvent('onload', runTests); |
| 30 | + } |
| 31 | + FikaScript.run = function(code) { |
| 32 | + runTest(code) |
| 33 | + } |
| 34 | + |
| 35 | + function runTests() { |
| 36 | + FikaScript.load('test.fika'); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + diff = function(source, dest) { |
| 41 | + for(index in source) { |
| 42 | + if (source[index] != dest[index]) { |
| 43 | + sourceStr = source.slice(0, index) + "<span class='diff'>X</span>" + source.slice(index); |
| 44 | + destStr = dest.slice(0, index) + "<span class='diff'>X</span>" + dest.slice(index); |
| 45 | + return [sourceStr, destStr]; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + runTest = function(code) { |
| 51 | + translation = FikaScript.swedishToEnglish(code); |
| 52 | + translation = FikaScript.englishToSwedish(translation); |
| 53 | + translation = FikaScript.swedishToEnglish(translation); |
| 54 | + translation = FikaScript.englishToSwedish(translation); |
| 55 | + code = code.replace(/\s/g, ''); |
| 56 | + translation = translation.replace(/\s/g, ''); |
| 57 | + if (code != translation) { |
| 58 | + diffs = diff(code, translation); |
| 59 | + document.getElementById('result').innerHTML = 'FAIL!'; |
| 60 | + document.getElementById('result').className = 'fail'; |
| 61 | + document.getElementById('codeDiff').style.display = 'inline-block'; |
| 62 | + document.getElementById('src').innerHTML = diffs[0]; |
| 63 | + document.getElementById('dest').innerHTML = diffs[1]; |
| 64 | + } else { |
| 65 | + document.getElementById('result').innerHTML = 'PASS!'; |
| 66 | + document.getElementById('result').className = 'success'; |
| 67 | + } |
| 68 | + } |
| 69 | + </script> |
| 70 | +</head> |
| 71 | +<body> |
| 72 | + |
| 73 | +<h1 id="result">Running....</h1> |
| 74 | +<div id="codeDiff"> |
| 75 | + <h3>Original</h3> |
| 76 | + <div id="src"></div> |
| 77 | + <h3>Final</h3> |
| 78 | + <div id="dest"></div> |
| 79 | +</div> |
| 80 | + |
| 81 | + |
| 82 | +</body> |
| 83 | +</html> |
0 commit comments