My agentic slop goes here. Not intended for anyone else!
1(* Basic tests for the textsize library *)
2
3let test name f =
4 try
5 f ();
6 Printf.printf "✓ %s\n" name
7 with e ->
8 Printf.printf "✗ %s: %s\n" name (Printexc.to_string e);
9 exit 1
10
11let () =
12 print_endline "Running textsize tests...\n";
13
14 (* Test scale validation *)
15 test "scale validation - valid range" (fun () ->
16 let _ = Termext.Textsize.v ~scale:1 () in
17 let _ = Termext.Textsize.v ~scale:7 () in
18 ()
19 );
20
21 test "scale validation - rejects invalid" (fun () ->
22 try
23 let _ = Termext.Textsize.v ~scale:0 () in
24 failwith "Should have raised Invalid_argument"
25 with Invalid_argument _ -> ()
26 );
27
28 (* Test width validation *)
29 test "width validation - valid range" (fun () ->
30 let _ = Termext.Textsize.v ~width:0 () in
31 let _ = Termext.Textsize.v ~width:7 () in
32 ()
33 );
34
35 (* Test escape sequence generation *)
36 test "double escape sequence" (fun () ->
37 let result = Termext.Textsize.double "test" in
38 assert (String.length result > 0);
39 assert (result = "\x1b]66;s=2;test\x07")
40 );
41
42 test "triple escape sequence" (fun () ->
43 let result = Termext.Textsize.triple "hello" in
44 assert (result = "\x1b]66;s=3;hello\x07")
45 );
46
47 test "half escape sequence" (fun () ->
48 let result = Termext.Textsize.half "tiny" in
49 assert (result = "\x1b]66;n=1:d=2;tiny\x07")
50 );
51
52 test "superscript escape sequence" (fun () ->
53 let result = Termext.Textsize.superscript "2" in
54 assert (result = "\x1b]66;n=1:d=2:v=2;2\x07")
55 );
56
57 test "subscript escape sequence" (fun () ->
58 let result = Termext.Textsize.subscript "2" in
59 assert (result = "\x1b]66;n=1:d=2:v=0;2\x07")
60 );
61
62 (* Test custom metadata *)
63 test "custom metadata - scale and width" (fun () ->
64 let metadata = Termext.Textsize.v ~scale:3 ~width:5 () in
65 let result = Termext.Textsize.render metadata "custom" in
66 assert (result = "\x1b]66;s=3:w=5;custom\x07")
67 );
68
69 test "custom metadata - fractional" (fun () ->
70 let metadata = Termext.Textsize.v ~fraction:(2, 3) () in
71 let result = Termext.Textsize.render metadata "frac" in
72 assert (result = "\x1b]66;n=2:d=3;frac\x07")
73 );
74
75 test "empty metadata" (fun () ->
76 let result = Termext.Textsize.render (Termext.Textsize.v ()) "plain" in
77 assert (result = "\x1b]66;;plain\x07")
78 );
79
80 (* Test text length validation *)
81 test "text length validation - accepts valid" (fun () ->
82 let text = String.make 4096 'a' in
83 let _ = Termext.Textsize.double text in
84 ()
85 );
86
87 test "text length validation - rejects oversized" (fun () ->
88 let text = String.make 4097 'a' in
89 try
90 let _ = Termext.Textsize.double text in
91 failwith "Should have raised Invalid_argument"
92 with Invalid_argument _ -> ()
93 );
94
95 print_endline "\n✓ All tests passed!"