Skip to content

Commit

Permalink
Extra wrapString tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 16, 2023
1 parent 0db37d8 commit dd4691c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test_graphics_wrapString.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function SHOULD_BE(b,a) {
var ta = E.toJS(a);
var tb = E.toJS(b);
if (ta!=tb) {
console.log("GOT :"+tb+"\nSHOULD BE:"+ta);
console.log("GOT :"+tb);
console.log("SHOULD BE:"+ta);
console.log("================");
b.forEach(l=>console.log(E.toJS(l), g.stringWidth(l)));
console.log("================");
Expand Down Expand Up @@ -49,6 +50,15 @@ g.clear().setFont("4x6");
lines = g.wrapString("A very LongWord is not here", 30);
SHOULD_BE(lines, ["A very","LongWor","d is","not","here"]);

// don't wrap on commas if long enough
g.clear().setFont("4x6");
lines = g.wrapString("Hello,world", 100);
SHOULD_BE(lines, ["Hello,world"]);
// wrap on commas
g.clear().setFont("4x6");
lines = g.wrapString("Hello,world", 30);
SHOULD_BE(lines, ["Hello,","world"]);

// normal wrap
g.clear().setFont("4x6");
lines = g.wrapString("Hello there lots of text here", 64);
Expand Down Expand Up @@ -87,8 +97,14 @@ g.clear().setFont("4x6");
lines = g.wrapString("\0\x12\x12\x81\0\x7F\xFF\xBF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\x7F\xFF\x1F\xFF\x8F\xFF\xC7\xF9\xE3\xFE1\xFF\xC0\xFF\xF8\x7F\xFF?\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xDF\xFF\xE0",1000)
SHOULD_BE(lines, ["\0\x12\x12\x81\0\x7F\xFF\xBF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\x7F\xFF\x1F\xFF\x8F\xFF\xC7\xF9\xE3\xFE1\xFF\xC0\xFF\xF8\x7F\xFF?\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xDF\xFF\xE0"]);

// 4x 8x8 bitmaps - should be split on lines
g.clear().setFont("4x6");
lines = g.wrapString("\0\x08\x08\1\1\2\3\4\5\6\7\8\0\x08\x08\1\1\2\3\4\5\6\7\8\0\x08\x08\1\1\2\3\4\5\6\7\8\0\x08\x08\1\1\2\3\4\5\6\7\8",12)
SHOULD_BE(lines, ["\0\x08\x08\1\1\2\3\4\5\6\7\8","\0\x08\x08\1\1\2\3\4\5\6\7\8","\0\x08\x08\1\1\2\3\4\5\6\7\8","\0\x08\x08\1\1\2\3\4\5\6\7\8"]);

// UTF8 chars - no wrapping expected
g.clear().setFont("4x6");
lines = g.wrapString("F\u00F6n K\u00FCr B\u00E4r", 200);
SHOULD_BE(lines, ["F\u00F6n K\u00FCr B\u00E4r"]);

result = ok;

0 comments on commit dd4691c

Please sign in to comment.