1// current state that this test checks: 2// 1. io input files are utf-8 3// 2. strings parsed from io input files are ascii/utf16/utf32 4// 3. io standard printing emits utf-8 5// 4. file read/write does not change string encodings 6// 5. argument treating is the same as for input code 7 8UnicodeTest := UnitTest clone do( 9 io := Path with("_build", "binaries", "io_static ") # Yep, ugly, but at least it works :) 10 11 wdPath := Path with(method(call message label pathComponent) call, "UnicodeTest-helper") 12 tempPath := Path with(wdPath, "UnicodeTest.tmp") 13 textPath := Path with(wdPath, "UnicodeTest.txt") 14 15 fileString := File with(textPath) contents 16 triQuoteString := \ 17"""Hello, world! 18Здравствуй, мир! 19この世界お。今日は! 20""" 21 monoQuoteString := "Hello, world!\nЗдравствуй, мир!\n" 22 monoQuoteString = monoQuoteString .. "この世界お。今日は!\n" 23 24 plat := System platform 25 isOnWindows := plat beginsWithSeq("Windows") or plat beginsWithSeq("mingw") 26 if(isOnWindows, 27 diffCmd := "diff -q --strip-trailing-cr ", 28 diffCmd := "diff -q " 29 ) 30 31 tempWrite := method(s, 32 File with(tempPath) openForUpdating truncateToSize(0) write(s) close 33 ) 34 35 tempSystem := method(s, 36 code := (io .. s) asMutable replaceSeq("$0", Path with(wdPath, "printer.io")) 37 if(isOnWindows, code := code replaceSeq("\n", "\\n")) 38 System system(code .. " > " .. tempPath) 39 ) 40 41 assertDiff := method( 42 outcome := System system(diffCmd .. tempPath .. " " .. textPath) 43 File with(tempPath) remove 44 assertTrue(outcome == 0) 45 ) 46 47 knownBugDiff := method( 48 File with(tempPath) remove 49 knownBug(System system(diffCmd .. tempPath .. " " .. textPath) == 0) 50 ) 51 52 testCompares := method( 53 # do not use assertEquals to avoid damaging terminal 54 assertTrue(triQuoteString asUTF8 == fileString asUTF8) 55 assertTrue(triQuoteString asUTF8 == monoQuoteString asUTF8) 56 assertTrue(triQuoteString asUTF8 == fileString asUTF8) 57 ) 58 59 testFileFile := method( 60 tempWrite(fileString) 61 assertDiff 62 ) 63 64 testFileTriQuote := method( 65 tempWrite(triQuoteString asUTF8) 66 assertDiff 67 ) 68 69 testFileMonoQuote := method( 70 tempWrite(monoQuoteString asUTF8) 71 assertDiff 72 ) 73 74 testPrintFile := method( 75 tempSystem("$0 --print fileString") 76 assertDiff 77 ) 78 79 testPrintTriQuote := method( 80 tempSystem("$0 --print triQuoteString") 81 assertDiff 82 ) 83 84 testPrintMonoQuote := method( 85 tempSystem("$0 --print monoQuoteString") 86 assertDiff 87 ) 88 89 testArgsMonoQuote := method( 90 tempSystem("$0 --arg \"" .. monoQuoteString asUTF8 .. "\"") 91 assertDiff 92 ) 93 94 testArgsTriQuote := method( 95 tempSystem("$0 --arg \"" .. triQuoteString asUTF8 .. "\"") 96 assertDiff 97 ) 98 99 testArgsFile := method( 100 tempSystem("$0 --arg \"" .. fileString asUTF8 .. "\"") 101 assertDiff 102 ) 103 104 testArgsEval := method( 105 // this removeLast thing is here to remove last "\n", 106 // which io interpreter adds after executing the code 107 string := monoQuoteString asMutable asUTF8 removeLast escape 108 tempSystem("-e \"\\\"#{string}\\\" println\"" interpolate) 109 assertDiff 110 ) 111 112) 113