-
Notifications
You must be signed in to change notification settings - Fork 323
Expand file tree
/
Copy pathStringTests.fs
More file actions
1309 lines (1070 loc) · 53.6 KB
/
StringTests.fs
File metadata and controls
1309 lines (1070 loc) · 53.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Fable.Tests.Strings
open System
open Util.Testing
open Fable.Tests.Util
open System.Globalization
#if FABLE_COMPILER
open Fable.Core
open Fable.Core.JsInterop
#endif
module M =
let f x = nameof x
// LINE SEPARATOR char doesn't cause an error #1283
let LINE_SEPARATOR = "\u2028"
let [<Literal>] aLiteral = "foo"
let notALiteral = "foo"
[<Literal>]
let formatCoordinateBody = "(%f,%f)"
[<Literal>]
let formatPrefix = "Person at coordinates"
[<Literal>]
let fullFormat = formatPrefix + formatCoordinateBody
type MyUnion = Bar of int * int | Foo1 of float | Foo3 | Foo4 of MyUnion
type Test(i: int) =
override _.ToString() = string(i + i)
type B() =
let mutable a = 5
override x.ToString() =
a <- a + 1
$"a=%O{a}"
let spr fmt =
let fmt = Printf.StringFormat<_>(fmt)
sprintf fmt
let containsInOrder (substrings: string list) (str: string) =
let mutable lastIndex = -1
substrings |> List.forall (fun s ->
let i = str.IndexOf(s)
let success = i >= 0 && i > lastIndex
lastIndex <- i
success)
let tests = testList "Strings" [
testCase "F# nameof works" <| fun () ->
M.f 12 |> equal "x"
nameof M |> equal "M"
nameof M.f |> equal "f"
testCase "String literal addition is optimized" <| fun () ->
"bar" + aLiteral |> equal "barfoo"
"bar" + notALiteral |> equal "barfoo"
testCase "String chunkBySize works" <| fun () -> // See #1296
"fffff" |> Seq.chunkBySize 3 |> Seq.map String |> Seq.toList
|> equal ["fff"; "ff"]
// StringBuilder
testCase "StringBuilder works" <| fun () ->
let sb = System.Text.StringBuilder()
sb.Append "Hello" |> ignore
sb.AppendLine () |> ignore
sb.AppendLine "World!" |> ignore
let expected = System.Text.StringBuilder()
.AppendFormat("Hello{0}World!{0}", Environment.NewLine)
.ToString()
sb.ToString() |> equal expected
testCase "StringBuilder.Length works" <| fun () ->
let sb = System.Text.StringBuilder()
sb.Append("Hello") |> ignore
// We don't test the AppendLine for Length because depending on the OS
// the result is different. Unix \n VS Windows \r\n
// sb.AppendLine() |> ignore
sb.Length |> equal 5
testCase "StringBuilder.ToString works with index and length" <| fun () ->
let sb = System.Text.StringBuilder()
sb.Append("Hello") |> ignore
sb.AppendLine() |> ignore
sb.ToString(2, 2) |> equal "ll"
testCase "StringBuilder.Clear works" <| fun () ->
let sb = new System.Text.StringBuilder()
sb.Append("1111") |> ignore
sb.Clear() |> ignore
sb.ToString() |> equal ""
testCase "StringBuilder.Append works with various overloads" <| fun () ->
let sb = System.Text.StringBuilder()
.Append(System.Text.StringBuilder "aaa")
.Append("bcd".ToCharArray())
.Append('/')
.Append(true)
.Append(5.2)
.Append(34)
.Append('x', 4)
let actual = sb.ToString().Replace(",", ".").ToLower()
actual |> equal "aaabcd/true5.234xxxx"
testCase "StringBuilder.AppendFormat works" <| fun () ->
let sb = System.Text.StringBuilder()
sb.AppendFormat("Hello{0}World{1}", " ", "!") |> ignore
sb.ToString() |> equal "Hello World!"
testCase "StringBuilder.AppendFormat with provider works" <| fun () ->
let sb = System.Text.StringBuilder()
sb.AppendFormat(CultureInfo.InvariantCulture, "Hello{0}World{1}", " ", "!") |> ignore
sb.ToString() |> equal "Hello World!"
testCase "StringBuilder.Chars works" <| fun () ->
let sb = System.Text.StringBuilder()
.Append("abc")
.Append("def")
sb.Chars(0) |> equal 'a'
sb.Chars(1) |> equal 'b'
sb.Chars(2) |> equal 'c'
sb.Chars(3) |> equal 'd'
sb.Chars(4) |> equal 'e'
sb.Chars(5) |> equal 'f'
testCase "StringBuilder.Chars throws when index is out of bounds" <| fun () ->
let sb = System.Text.StringBuilder()
.Append("abc")
throwsAnyError <| fun () ->
sb.Chars(-1) |> ignore
throwsAnyError <| fun () ->
sb.Chars(3) |> ignore
testCase "StringBuilder.Replace works" <| fun () ->
let sb = System.Text.StringBuilder()
.Append("abc")
.Append("abc")
.Replace('a', 'x')
.Replace("cx", "yz")
sb.ToString() |> equal "xbyzbc"
testCase "StringBuilder index getter works" <| fun () ->
let sb = System.Text.StringBuilder()
.Append("abc")
sb[1] |> equal 'b'
testCase "StringBuilder index setter works" <| fun () ->
let sb = System.Text.StringBuilder()
.Append("abc")
sb[1] <- 'x'
sb.ToString() |> equal "axc"
throwsAnyError <| fun () ->
sb[-1] <- 'y'
throwsAnyError <| fun () ->
sb[3] <- 'z'
// Formatting
testCase "kprintf works" <| fun () ->
let f (s:string) = s + "XX"
Printf.kprintf f "hello" |> equal "helloXX"
Printf.kprintf f "%X" 255 |> equal "FFXX"
Printf.kprintf f "%.2f %g" 0.5468989 5. |> equal "0.55 5XX"
testCase "kprintf works indirectly" <| fun () -> // See #1204
let lines = ResizeArray<string>()
let linef fmt = Printf.ksprintf lines.Add fmt // broken
linef "open %s" "Foo"
lines |> Seq.toList |> equal ["open Foo"]
testCase "kbprintf works" <| fun () ->
let sb = System.Text.StringBuilder()
let mutable i = 0
let f () = i <- i + 1
Printf.kbprintf f sb "Hello"
Printf.kbprintf f sb " %s!" "world"
i |> equal 2
sb.ToString() |> equal "Hello world!"
testCase "ksprintf curries correctly" <| fun () ->
let append (a: string) b = a + b
let step1 = Printf.ksprintf append "%d"
let step2 = step1 42
let result = step2 "The answer is: "
result |> equal "42The answer is: "
testCase "bprintf works" <| fun () ->
let sb = System.Text.StringBuilder(10)
Printf.bprintf sb "Hello"
Printf.bprintf sb " %s!" "world"
sb.ToString() |> equal "Hello world!"
testCase "sprintf works" <| fun () ->
// Immediately applied
sprintf "%.2f %g" 0.5468989 5.
|> equal "0.55 5"
// Curried
let printer = sprintf "Hi %s, good %s!"
let printer = printer "Alfonso"
printer "morning" |> equal "Hi Alfonso, good morning!"
printer "evening" |> equal "Hi Alfonso, good evening!"
testCase "sprintf works II" <| fun () ->
let printer2 = sprintf "Hi %s, good %s%s" "Maxime"
let printer2 = printer2 "afternoon"
printer2 "?" |> equal "Hi Maxime, good afternoon?"
testCase "sprintf with different decimal digits works" <| fun () -> // See #1932
sprintf "Percent: %.0f%%" 5.0 |> equal "Percent: 5%"
sprintf "Percent: %.2f%%" 5. |> equal "Percent: 5.00%"
sprintf "Percent: %.1f%%" 5.24 |> equal "Percent: 5.2%"
sprintf "Percent: %.2f%%" 5.268 |> equal "Percent: 5.27%"
sprintf "Percent: %f%%" 5.67 |> equal "Percent: 5.670000%"
testCase "sprintf displays sign correctly" <| fun () -> // See #1937
sprintf "%i" 1 |> equal "1"
sprintf "%d" 1 |> equal "1"
sprintf "%d" 1L |> equal "1"
sprintf "%.2f" 1. |> equal "1.00"
sprintf "%i" -1 |> equal "-1"
sprintf "%d" -1 |> equal "-1"
sprintf "%d" -1L |> equal "-1"
sprintf "%.2f" -1. |> equal "-1.00"
testCase "format string can use and compose string literals" <| fun () ->
let renderedCoordinates = sprintf formatCoordinateBody 0.25 0.75
let renderedText = sprintf fullFormat 0.25 0.75
equal "(0.250000,0.750000)" renderedCoordinates
equal "Person at coordinates(0.250000,0.750000)" renderedText
testCase "Print.sprintf works" <| fun () -> // See #1216
let res = Printf.sprintf "%s" "abc"
equal "res: abc" ("res: " + res)
testCase "sprintf without arguments works" <| fun () ->
sprintf "hello" |> equal "hello"
testCase "input of print format can be retrieved" <| fun () ->
let pathScan (pf:PrintfFormat<_,_,_,_,'t>) =
let formatStr = pf.Value
formatStr
equal "/hello/%s" (pathScan "/hello/%s")
testCase "sprintf with escaped percent symbols works" <| fun () -> // See #195
let r, r1, r2 = "Ratio", 0.213849, 0.799898
sprintf "%s1: %.2f%% %s2: %.2f%%" r (r1*100.) r (r2*100.)
|> equal "Ratio1: 21.38% Ratio2: 79.99%"
testCase "sprintf with percent symbols in arguments works" <| fun () -> // See #329
let same s = sprintf "%s" s |> equal s
same "%"
same "%%"
same "%%%"
same "%%%%"
same "% %"
same "%% %%"
same "%% % % %%"
testCase "Fix #2398: Exception when two successive string format placeholders and value of first one ends in `%`" <| fun () ->
sprintf "%c%s" '%' "text" |> equal "%text"
testCase "Unions with sprintf %A" <| fun () ->
Bar(1,5) |> sprintf "%A" |> equal "Bar (1, 5)"
Foo1 4.5 |> sprintf "%A" |> equal "Foo1 4.5"
Foo4 Foo3 |> sprintf "%A" |> equal "Foo4 Foo3"
Foo4(Foo1 4.5) |> sprintf "%A" |> equal "Foo4 (Foo1 4.5)"
Foo3 |> sprintf "%A" |> equal "Foo3"
testCase "Unions with string operator" <| fun () ->
Bar(1,5) |> string |> equal "Bar (1, 5)"
Foo1 4.5 |> string |> equal "Foo1 4.5"
Foo4 Foo3 |> string |> equal "Foo4 Foo3"
Foo4(Foo1 4.5) |>string |> equal "Foo4 (Foo1 4.5)"
Foo3 |> string |> equal "Foo3"
testCase "sprintf \"%O\" with overloaded string works" <| fun () ->
let o = Test(5)
sprintf "%O" o |> equal "10"
testCase "sprintf \"%A\" with overloaded string works" <| fun () ->
let o = Test(5)
(sprintf "%A" o).Replace("\"", "") |> equal "10"
#if FABLE_COMPILER
testCase "sprintf \"%A\" with circular references doesn't crash" <| fun () -> // See #338
let o = obj()
o?self <- o
sprintf "%A" o |> ignore
#endif
testCase "string interpolation works" <| fun () ->
let name = "Phillip"
let age = 29
sprintf $"Name: %s{name}, Age: %i{age}"
|> equal "Name: Phillip, Age: 29"
testCase "string interpolation works with inline expressions" <| fun () ->
$"I think {3.0 + 0.14} is close to %.8f{Math.PI}!".Replace(",", ".")
|> equal "I think 3.14 is close to 3.14159265!"
testCase "string interpolation works with anonymous records" <| fun () ->
let person =
{|
Name = "John"
Surname = "Doe"
Age = 32
Country = "The United Kingdom"
|}
$"Hi! My name is %s{person.Name} %s{person.Surname.ToUpper()}. I'm %i{person.Age} years old and I'm from %s{person.Country}!"
|> equal "Hi! My name is John DOE. I'm 32 years old and I'm from The United Kingdom!"
testCase "Printf %A works with anonymous records" <| fun () -> // See #4029
let person = {| FirstName = "John"; LastName = "Doe" |}
let s = sprintf "%A" person
System.Text.RegularExpressions.Regex.Replace(s.Replace("\"", ""), @"\s+", " ")
|> equal """{ FirstName = John LastName = Doe }"""
testCase "Interpolated strings keep empty lines" <| fun () ->
let s1 = $"""1
{1+1}
3"""
let s2 = """1
2
3"""
equal s1 s2
equal s1.Length s2.Length
equal 13 s1.Length
testCase "Can use backslash is interpolated strings" <| fun () ->
$"\n{1+1}\n" |> equal """
2
"""
testCase "Backslash is escaped in interpolated strings" <| fun () -> // See #2649
$"\\" |> equal @"\"
$"\\".Length |> equal 1
$@"\" |> equal @"\"
$@"\".Length |> equal 1
@$"\" |> equal @"\"
@$"\".Length |> equal 1
$"\\{4}" |> equal @"\4"
$"\\{4}".Length |> equal 2
$@"\{4}" |> equal @"\4"
$@"\{4}".Length |> equal 2
@$"\{4}" |> equal @"\4"
@$"\{4}".Length |> equal 2
testCase "%O in interpolated strings works recursively" <| fun () -> // See #3078
let b = B()
$"b=(%O{b})" |> equal "b=(a=6)"
$"%O{b}%O{b}" |> equal "a=7a=8"
testCase "Extended string interpolation syntax" <| fun () ->
let classAttr = "item-panel"
let cssNew = $$""".{{classAttr}}:hover {background-color: #eee;}"""
cssNew |> equal ".item-panel:hover {background-color: #eee;}"
testCase "Interpolated strings with .NET numeric format specifiers work" <| fun () -> // See #4046
let n = 1000000
$"{n:N0}" |> equal "1,000,000"
$"{n:N2}" |> equal "1,000,000.00"
$"Count: {n:N0} items" |> equal "Count: 1,000,000 items"
let f = 1234.5
$"{f:F2}" |> equal "1234.50"
testCase "Interpolated strings with .NET custom format specifiers work" <| fun () -> // See #4046
let n = 1000
$"{n:#,#}" |> equal "1,000"
$"{n:#,#} items" |> equal "1,000 items"
testCase "sprintf \"%A\" with lists works" <| fun () ->
let xs = ["Hi"; "Hello"; "Hola"]
(sprintf "%A" xs).Replace("\"", "") |> equal "[Hi; Hello; Hola]"
testCase "sprintf \"%A\" with nested lists works" <| fun () ->
let xs = [["Hi"]; ["Hello"]; ["Hola"]]
(sprintf "%A" xs).Replace("\"", "") |> equal "[[Hi]; [Hello]; [Hola]]"
testCase "sprintf \"%A\" with sequences works" <| fun () ->
let xs = seq { "Hi"; "Hello"; "Hola" }
sprintf "%A" xs |> containsInOrder ["Hi"; "Hello"; "Hola"] |> equal true
testCase "Storing result of Seq.tail and printing the result several times works. Related to #1996" <| fun () ->
let tweets = seq { "Hi"; "Hello"; "Hola" }
let tweetsTailR: seq<string> = tweets |> Seq.tail
let a = sprintf "%A" (tweetsTailR)
let b = sprintf "%A" (tweetsTailR)
containsInOrder ["Hello"; "Hola"] a |> equal true
containsInOrder ["Hello"; "Hola"] b |> equal true
testCase "sprintf \"%X\" works" <| fun () ->
//These should all be the Native JS Versions (except int64 / uint64)
//See #1530 for more information.
sprintf "255: %X" 255 |> equal "255: FF"
sprintf "255: %x" 255 |> equal "255: ff"
sprintf "-255: %X" -255 |> equal "-255: FFFFFF01"
sprintf "4095L: %X" 4095L |> equal "4095L: FFF"
sprintf "-4095L: %X" -4095L |> equal "-4095L: FFFFFFFFFFFFF001"
sprintf "1 <<< 31: %x" (1 <<< 31) |> equal "1 <<< 31: 80000000"
sprintf "1u <<< 31: %x" (1u <<< 31) |> equal "1u <<< 31: 80000000"
sprintf "2147483649L: %x" 2147483649L |> equal "2147483649L: 80000001"
sprintf "2147483650uL: %x" 2147483650uL |> equal "2147483650uL: 80000002"
sprintf "1L <<< 63: %x" (1L <<< 63) |> equal "1L <<< 63: 8000000000000000"
sprintf "1uL <<< 63: %x" (1uL <<< 63) |> equal "1uL <<< 63: 8000000000000000"
testCase "sprintf integers with sign and padding works" <| fun () -> // See #1931
sprintf "%+04i" 1 |> equal "+001"
sprintf "%+04i" -1 |> equal "-001"
sprintf "%5d" -5 |> equal " -5"
sprintf "%5d" -5L |> equal " -5"
sprintf "%- 4i" 5 |> equal " 5 "
testCase "parameterized padding works" <| fun () -> // See #2336
sprintf "[%*s][%*s]" 6 "Hello" 5 "Foo"
|> equal "[ Hello][ Foo]"
testCase "String.Format should fail if there are less arguments than placeholders" <| fun () -> // See #2768
throwsAnyError <| fun () -> String.Format ("Hello {0}", args = Array.empty)
testCase "String.Format combining padding and zeroes pattern works" <| fun () ->
String.Format(CultureInfo.InvariantCulture, "{0:++0.00++}", -5000.5657) |> equal "-++5000.57++"
String.Format(CultureInfo.InvariantCulture, "{0:000.00}foo", 5) |> equal "005.00foo"
String.Format(CultureInfo.InvariantCulture, "{0,-8:000.00}foo", 12.456) |> equal "012.46 foo"
testCase "String.Format {0:x} works" <| fun () ->
//See above comment on expected values
String.Format(CultureInfo.InvariantCulture, "255: {0:X}", 255) |> equal "255: FF"
String.Format(CultureInfo.InvariantCulture, "255: {0:x}", 255) |> equal "255: ff"
String.Format(CultureInfo.InvariantCulture, "-255: {0:X}", -255) |> equal "-255: FFFFFF01"
String.Format(CultureInfo.InvariantCulture, "4095L: {0:X}", 4095L) |> equal "4095L: FFF"
String.Format(CultureInfo.InvariantCulture, "-4095L: {0:X}", -4095L) |> equal "-4095L: FFFFFFFFFFFFF001"
String.Format(CultureInfo.InvariantCulture, "1 <<< 31: {0:x}", (1 <<< 31)) |> equal "1 <<< 31: 80000000"
String.Format(CultureInfo.InvariantCulture, "1u <<< 31: {0:x}", (1u <<< 31)) |> equal "1u <<< 31: 80000000"
String.Format(CultureInfo.InvariantCulture, "2147483649L: {0:x}", 2147483649L) |> equal "2147483649L: 80000001"
String.Format(CultureInfo.InvariantCulture, "2147483650uL: {0:x}", 2147483650uL) |> equal "2147483650uL: 80000002"
String.Format(CultureInfo.InvariantCulture, "1L <<< 63: {0:x}", (1L <<< 63)) |> equal "1L <<< 63: 8000000000000000"
String.Format(CultureInfo.InvariantCulture, "1uL <<< 63: {0:x}", (1uL <<< 63)) |> equal "1uL <<< 63: 8000000000000000"
testCase "String.Format {0:x} with precision works" <| fun () ->
String.Format(CultureInfo.InvariantCulture, "#{0:X3}", 0xC149D) |> equal "#C149D"
String.Format(CultureInfo.InvariantCulture, "#{0:X6}", 0xC149D) |> equal "#0C149D"
testCase "String.Format works with thousands separator" <| fun () ->
String.Format(CultureInfo.InvariantCulture, "{0}", 12343235354.6547757) |> equal "12343235354.654776"
String.Format(CultureInfo.InvariantCulture, "{0:#,##.000}", 12343235354.6547757) |> equal "12,343,235,354.655"
String.Format(CultureInfo.InvariantCulture, "{0:#,##.000}", 12343235354.6547757M) |> equal "12,343,235,354.655"
String.Format(CultureInfo.InvariantCulture, "{0:#,##.00}", 123.456) |> equal "123.46"
String.Format(CultureInfo.InvariantCulture, "{0:#,##.00}", 123.456M) |> equal "123.46"
String.Format(CultureInfo.InvariantCulture, "{0:#,##.00}", 123438192123.456M) |> equal "123,438,192,123.46"
String.Format(CultureInfo.InvariantCulture, "{0:#,##}", 1.456M) |> equal "1"
String.Format(CultureInfo.InvariantCulture, "{0:0,0}", 1.456M) |> equal "01"
testCase "String.Format can omit decimal digits" <| fun () ->
String.Format(CultureInfo.InvariantCulture, "{0:#,##}", 12343235354.6547757) |> equal "12,343,235,355"
String.Format(CultureInfo.InvariantCulture, "{0:0,00}", 12343235354.6547757) |> equal "12,343,235,355"
String.Format(CultureInfo.InvariantCulture, "{0:0,00}", 12343235354.) |> equal "12,343,235,354"
String.Format(CultureInfo.InvariantCulture, "{0:#}", 12343235354.) |> equal "12343235354"
String.Format(CultureInfo.InvariantCulture, "{0:0}", 12343235354.) |> equal "12343235354"
String.Format(CultureInfo.InvariantCulture, "{0:#,#}", 12343235354.6547757M) |> equal "12,343,235,355"
String.Format(CultureInfo.InvariantCulture, "{0:0,0}", 12343235354.6547757M) |> equal "12,343,235,355"
String.Format(CultureInfo.InvariantCulture, "{0:0,0}", 1234323535) |> equal "1,234,323,535"
String.Format(CultureInfo.InvariantCulture, "{0:#}", 1234323535) |> equal "1234323535"
String.Format(CultureInfo.InvariantCulture, "{0:0}", 1234323535) |> equal "1234323535"
String.Format(CultureInfo.InvariantCulture, "{0:0,0}", 12343235354M) |> equal "12,343,235,354"
String.Format(CultureInfo.InvariantCulture, "{0:0,0}", 343235354M) |> equal "343,235,354"
String.Format(CultureInfo.InvariantCulture, "{0:#}", 12343235354M) |> equal "12343235354"
String.Format(CultureInfo.InvariantCulture, "{0:0}", 12343235354M) |> equal "12343235354"
testCase "String.Format works with N format specifier" <| fun () -> // See #2582
String.Format(CultureInfo.InvariantCulture, "{0:N0}", 1000) |> equal "1,000"
String.Format(CultureInfo.InvariantCulture, "{0:N0}", 12345678) |> equal "12,345,678"
String.Format(CultureInfo.InvariantCulture, "{0:N0}", -1000) |> equal "-1,000"
String.Format(CultureInfo.InvariantCulture, "{0:N2}", 1000) |> equal "1,000.00"
String.Format(CultureInfo.InvariantCulture, "{0:N}", 1000) |> equal "1,000.00"
(1000).ToString("N0") |> equal "1,000"
(1000).ToString("N2") |> equal "1,000.00"
testCase "String.Format trims trailing zeroes when using # placeholder" <| fun () -> // Fix #2950
String.Format(CultureInfo.InvariantCulture, "{0:######,###.000####}", -6789.5688) |> equal "-6,789.5688"
String.Format(CultureInfo.InvariantCulture, "{0:######,###.000####}", 6789.5688) |> equal "6,789.5688"
String.Format(CultureInfo.InvariantCulture, "{0:0######,###.000####0}", -6789.5688) |> equal "-0,000,006,789.56880000"
String.Format(CultureInfo.InvariantCulture, "{0:0######,###.000####0}", 6789.5688) |> equal "0,000,006,789.56880000"
testCase "C and P format specifiers work with zero precision" <| fun () -> // See #2582
String.Format(CultureInfo.InvariantCulture, "{0:C0}", 1000) |> equal "¤1,000"
String.Format(CultureInfo.InvariantCulture, "{0:C0}", -1000) |> equal "(¤1,000)"
String.Format(CultureInfo.InvariantCulture, "{0:P0}", 0.5) |> equal "50 %"
String.Format(CultureInfo.InvariantCulture, "{0:P2}", 0.1234) |> equal "12.34 %"
String.Format(CultureInfo.InvariantCulture, "{0:C2}", 1000) |> equal "¤1,000.00"
testCase "ToString formatted works with decimals" <| fun () -> // See #2276
let decimal = 78.6M
decimal.ToString("0.000").Replace(",", ".") |> equal "78.600"
testCase "Printf works with generic argument" <| fun () ->
spr "bar %s" "a" |> equal "bar a"
spr "foo %i %i" 3 5 |> equal "foo 3 5"
let f1 = spr "foo %i %i"
let f2 = f1 2
f2 2 |> equal "foo 2 2"
let f1 = spr "foo %i %i %i"
let f2 = f1 2
let f3 = f2 2
f3 2 |> equal "foo 2 2 2"
testCase "Printf in sequence is not erased" <| fun () ->
let x = sprintf "Foo"
let y = sprintf "B%sr" "a"
x + y |> equal "FooBar"
testCase "String slicing works" <| fun () ->
let s = "cat and dog"
sprintf "%s" s.[2..8] |> equal "t and d"
sprintf "%s" s.[2..] |> equal "t and dog"
sprintf "%s" s.[..8] |> equal "cat and d"
testCase "String.Format works" <| fun () ->
let arg1, arg2, arg3 = "F#", "Fable", "Babel"
String.Format(CultureInfo.InvariantCulture, "{2} is to {1} what {1} is to {0}", arg1, arg2, arg3)
|> equal "Babel is to Fable what Fable is to F#"
testCase "String.Format with extra formatting works" <| fun () ->
let i = 0.5466788
let dt = DateTime(2014, 9, 26).AddMinutes(19.)
String.Format(CultureInfo.InvariantCulture, "{0:F2} {0:P2} {1:yyyy-MM-dd HH:mm}", i, dt)
.Replace(",", ".").Replace(" %", "%")
|> equal "0.55 54.67% 2014-09-26 00:19"
testCase "Padding works" <| fun () ->
"3.14".PadLeft(10) |> equal " 3.14"
"3.14".PadRight(10) |> equal "3.14 "
"22".PadLeft(10, '0') |> equal "0000000022"
"-22".PadRight(10, 'X') |> equal "-22XXXXXXX"
"333".PadLeft(1) |> equal "333"
testCase "Padding with sprintf works" <| fun () ->
sprintf "%10.1f" 3.14 |> equal " 3.1"
sprintf "%-10.1f" 3.14 |> equal "3.1 "
sprintf "%+010i" 22 |> equal "+000000022"
sprintf "%+0-10i" -22 |> equal "-22 "
testCase "Padding with String.Format works" <| fun () ->
String.Format(CultureInfo.InvariantCulture, "{0,10:F1}", 3.14) |> equal " 3.1"
String.Format(CultureInfo.InvariantCulture, "{0,-10:F1}", 3.14) |> equal "3.1 "
String.Format(CultureInfo.InvariantCulture, "{0,10}", 22) |> equal " 22"
String.Format(CultureInfo.InvariantCulture, "{0,-10}", -22) |> equal "-22 "
// Conversions
testCase "Conversion char to int works" <| fun () ->
equal 97 (int 'a')
equal 'a' (char 97)
testCase "Conversion string to char works" <| fun () ->
equal 'a' (char "a")
equal "a" (string 'a')
testCase "Conversion string to negative int8 works" <| fun () ->
equal -5y (int8 "-5")
equal "-5" (string -5y)
testCase "Conversion string to negative int16 works" <| fun () ->
equal -5s (int16 "-5")
equal "-5" (string -5s)
testCase "Conversion string to negative int32 works" <| fun () ->
equal -5 (int32 "-5")
equal "-5" (string -5)
testCase "Conversion string to negative int64 works" <| fun () ->
equal -5L (int64 "-5")
equal "-5" (string -5L)
testCase "Conversion string to int8 works" <| fun () ->
equal 5y (int8 "5")
equal "5" (string 5y)
testCase "Conversion string to int16 works" <| fun () ->
equal 5s (int16 "5")
equal "5" (string 5s)
testCase "Conversion string to int32 works" <| fun () ->
equal 5 (int32 "5")
equal "5" (string 5)
testCase "Conversion string to int64 works" <| fun () ->
equal 5L (int64 "5")
equal "5" (string 5L)
testCase "Conversion string to uint8 works" <| fun () ->
equal 5uy (uint8 "5")
equal "5" (string 5uy)
testCase "Conversion string to uint16 works" <| fun () ->
equal 5us (uint16 "5")
equal "5" (string 5us)
testCase "Conversion string to uint32 works" <| fun () ->
equal 5u (uint32 "5")
equal "5" (string 5u)
testCase "Conversion string to uint64 works" <| fun () ->
equal 5uL (uint64 "5")
equal "5" (string 5uL)
testCase "Conversion string to single works" <| fun () ->
equal 5.f (float32 "5.0")
equal -5.f (float32 "-5.0")
(string 5.f).StartsWith("5") |> equal true
equal 5.25f (float32 "5.25")
(string 5.25f).StartsWith("5.25") |> equal true
testCase "Conversion string to double works" <| fun () ->
equal 5. (float "5.0")
equal -5. (float "-5.0")
(string 5.).StartsWith("5") |> equal true
equal 5.25 (float "5.25")
(string 5.25).StartsWith("5.25") |> equal true
testCase "Conversion string to decimal works" <| fun () ->
equal 5.m (decimal "5.0")
equal -5.m (decimal "-5.0")
(string 5.m).StartsWith("5") |> equal true
equal 5.25m (decimal "5.25")
(string 5.25m).StartsWith("5.25") |> equal true
// System.String - constructors
testCase "String.ctor(char[]) works" <| fun () ->
System.String([|'f'; 'a'; 'b'; 'l'; 'e'|])
|> equal "fable"
testCase "String.ctor(char, int) works" <| fun () ->
System.String('f', 5)
|> equal "fffff"
testCase "String.ctor(char[], int, int) works" <| fun () ->
System.String([|'f'; 'a'; 'b'; 'l'; 'e'|], 1, 3)
|> equal "abl"
// System.String - static methods
testCase "System.String.Equals works" <| fun () ->
System.String.Equals("abc", "abc") |> equal true
// TypeScript will complain if we use equality with two different literals
let mutable a = "a" // make it mutable so Fable doesn't inline it
System.String.Equals("ABC", a + "bc") |> equal false
System.String.Equals("abc", a + "bd") |> equal false
"abc".Equals("abc") |> equal true
"ABC".Equals(a + "bc") |> equal false
"abc".Equals(a + "bd") |> equal false
System.String.Equals("ABC", "abc", StringComparison.Ordinal) |> equal false
System.String.Equals("ABC", "abc", StringComparison.OrdinalIgnoreCase) |> equal true
"ABC".Equals("abc", StringComparison.Ordinal) |> equal false
"ABC".Equals("abc", StringComparison.OrdinalIgnoreCase) |> equal true
testCase "String.Compare works" <| fun () ->
"ABC".CompareTo("abc") > 0 |> equal true
System.String.Compare("abc", "abc") |> equal 0
System.String.Compare("ABC", "abc") |> equal 1
System.String.Compare("abc", "abd") |> equal -1
System.String.Compare("bbc", "abd") |> equal 1
System.String.Compare("ABC", "abc", false) |> equal 1
System.String.Compare("ABC", "abc", true) |> equal 0
System.String.Compare("ABC", "abd", true) |> equal -1
System.String.Compare("BBC", "abd", true) |> equal 1
System.String.Compare("ABC", "abc", StringComparison.CurrentCulture) > 0 |> equal true
System.String.Compare("ABC", "abc", StringComparison.Ordinal) < 0 |> equal true
System.String.Compare("ABC", "abc", StringComparison.OrdinalIgnoreCase) |> equal 0
System.String.Compare("abc", 0, "bcd", 0, 3) |> equal -1
System.String.Compare("abc", 1, "bcd", 0, 2) |> equal 0
System.String.Compare("ABC", 1, "bcd", 0, 2, StringComparison.CurrentCulture) > 0 |> equal true
System.String.Compare("ABC", 1, "bcd", 0, 2, StringComparison.Ordinal) < 0 |> equal true
System.String.Compare("ABC", 1, "bcd", 0, 2, StringComparison.OrdinalIgnoreCase) |> equal 0
testCase "String.IsNullOrEmpty works" <| fun () ->
let args = [("", true); (null, true); ("test", false); (" \t", false)]
for arg in args do
System.String.IsNullOrEmpty(fst arg)
|> equal (snd arg)
testCase "String.IsNullOrWhiteSpace works" <| fun () ->
let args = [("", true); (null, true); ("test", false); (" \t", true)]
for arg in args do
System.String.IsNullOrWhiteSpace(fst arg)
|> equal (snd arg)
// System.String - instance methods
testCase "String.Contains works" <| fun () ->
"ABC".Contains("B") |> equal true
"ABC".Contains("Z") |> equal false
testCase "String.Contains with StringComparison works" <| fun () ->
"ABC".Contains("b", StringComparison.Ordinal) |> equal false
"ABC".Contains("b", StringComparison.OrdinalIgnoreCase) |> equal true
"ABC".Contains("b", StringComparison.InvariantCultureIgnoreCase) |> equal true
testCase "String.Split works" <| fun () ->
"a b c d".Split(' ')
|> equal [|"a";"b";"c";"";"d"|]
"a b c d ".Split()
|> equal [|"a";"b";"c";"";"d";""|]
"a-b-c".Split()
|> equal [|"a-b-c"|]
"a-b-c".Split("")
|> equal [|"a-b-c"|]
"a\tb".Split()
|> equal [|"a";"b"|]
"a\nb".Split()
|> equal [|"a";"b"|]
"a\rb".Split()
|> equal [|"a";"b"|]
"a\u2003b".Split() // em space
|> equal [|"a";"b"|]
"a b c d".Split(null)
|> equal [|"a";"b";"c";"";"d"|]
"a\tb".Split(null)
|> equal [|"a";"b"|]
"a\u2003b".Split(null) // em space
|> equal [|"a";"b"|]
let array = "a;b,c".Split(',', ';')
"abc" = array.[0] + array.[1] + array.[2]
|> equal true
"a--b-c".Split([|"--"|], StringSplitOptions.None)
|> equal [|"a";"b-c"|]
" a-- b- c ".Split('-', 2, StringSplitOptions.None)
|> equal [|" a"; "- b- c "|]
"---o---o---".Split("--", StringSplitOptions.None)
|> equal [|""; "-o"; "-o"; "-"|];
testCase "String.Split with remove empties works" <| fun () ->
"a b c d ".Split([|" "|], StringSplitOptions.RemoveEmptyEntries)
|> (=) [|"a";"b";"c";"d"|] |> equal true
" a-- b- c ".Split("-", 2, StringSplitOptions.RemoveEmptyEntries)
|> (=) [|" a"; " b- c "|] |> equal true
"---o---o---".Split("--", StringSplitOptions.RemoveEmptyEntries)
|> (=) [|"-o"; "-o"; "-"|] |> equal true
let array = ";,a;b,c".Split([|','; ';'|], StringSplitOptions.RemoveEmptyEntries)
"abc" = array.[0] + array.[1] + array.[2]
|> equal true
testCase "String.Split with count works" <| fun () ->
let array = "a b c d".Split ([|' '|], 2)
equal "a" array.[0]
equal "b c d" array.[1]
"a;,b,c;d".Split([|','; ';'|], 3, StringSplitOptions.RemoveEmptyEntries)
|> (=) [|"a";"b";"c;d"|] |> equal true
"a-b-c".Split("", System.Int32.MaxValue)
|> (=) [|"a-b-c"|] |> equal true
testCase "String.Split with empty works" <| fun () ->
let array = "a b cd".Split()
array |> equal [| "a"; "b"; "cd" |]
testCase "String.Split with trim entries works" <| fun () ->
" a-- b- c ".Split('-', 2, StringSplitOptions.TrimEntries)
|> (=) [|"a"; "- b- c"|] |> equal true
" a-- b- c ".Split('-', 3, StringSplitOptions.TrimEntries)
|> (=) [|"a"; ""; "b- c"|] |> equal true
testCase "String.Split with trim and remove entries works" <| fun () ->
" a-- b- c ".Split([| "-" |], 2, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
|> equal [|"a"; "b- c"|]
" a-- b- c ".Split([| '-' |], 3, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
|> equal [|"a"; "b"; "c"|]
testCase "String.Split with consecutive separators works" <| fun () ->
" ".Split(" ", 4, StringSplitOptions.None)
|> equal [|"";"";"";" "|]
" ".Split(" ", 4, StringSplitOptions.RemoveEmptyEntries)
|> equal [||]
" ".Split(" ", 4, StringSplitOptions.TrimEntries)
|> equal [|"";"";"";""|]
" ".Split(" ", 4, StringSplitOptions.RemoveEmptyEntries ||| StringSplitOptions.TrimEntries)
|> equal [||]
testCase "String.Replace works" <| fun () ->
"abc abc abc".Replace("abc", "d") |> equal "d d d"
// String.Replace does not get stuck in endless loop
"...".Replace(".", "..") |> equal "......"
testCase "Access char by index works" <| fun () ->
let c = "abcd".[2]
equal 'c' c
equal 'd' (char ((int c) + 1))
testCase "String.IndexOf char works" <| fun () ->
"abcd".IndexOf('b') * 100 + "abcd".IndexOf('e')
|> equal 99
testCase "String.IndexOf char works with offset" <| fun () ->
"abcdbc".IndexOf('b', 3)
|> equal 4
testCase "String.IndexOf with StringComparison" <| fun () ->
"abcdbc".IndexOf("b", StringComparison.Ordinal)
|> equal 1
testCase "String.IndexOf with index and StringComparison" <| fun () ->
"abcdbc".IndexOf("b", 3, StringComparison.Ordinal)
|> equal 4
testCase "String.LastIndexOf char works" <| fun () ->
"abcdbc".LastIndexOf('b') * 100 + "abcd".LastIndexOf('e')
|> equal 399
testCase "String.LastIndexOf char works with offset" <| fun () ->
"abcdbcebc".LastIndexOf('b', 3)
|> equal 1
testCase "String.LastIndexOf with StringComparison" <| fun () ->
"abcdbc".LastIndexOf("b", StringComparison.Ordinal)
|> equal 4
testCase "String.LastIndexOf with index and StringComparison" <| fun () ->
"abcdbc".LastIndexOf("b", 3, StringComparison.Ordinal)
|> equal 1
testCase "String.IndexOf works" <| fun () ->
"abcd".IndexOf("bc") * 100 + "abcd".IndexOf("bd")
|> equal 99
testCase "String.IndexOf works with offset" <| fun () ->
"abcdbc".IndexOf("bc", 3)
|> equal 4
testCase "String.LastIndexOf works" <| fun () ->
"abcdbc".LastIndexOf("bc") * 100 + "abcd".LastIndexOf("bd")
|> equal 399
testCase "String.LastIndexOf works with offset" <| fun () ->
"abcdbcebc".LastIndexOf("bc", 3)
|> equal 1
testCase "String.IndexOfAny works" <| fun () ->
"abcdbcebc".IndexOfAny([|'b'|]) |> equal 1
"abcdbcebc".IndexOfAny([|'b'|], 2) |> equal 4
"abcdbcebc".IndexOfAny([|'b'|], 2, 2) |> equal -1
"abcdbcebc".IndexOfAny([|'f';'e'|]) |> equal 6
"abcdbcebc".IndexOfAny([|'f';'e'|], 2) |> equal 6
"abcdbcebc".IndexOfAny([|'f';'e'|], 2, 4) |> equal -1
"abcdbcebc".IndexOfAny([|'c';'b'|]) |> equal 1
// testCase "String.StartsWith char works" <| fun () ->
// "abcd".StartsWith('a') |> equal true
// "abcd".StartsWith('d') |> equal false
// testCase "String.EndsWith char works" <| fun () ->
// "abcd".EndsWith('a') |> equal false
// "abcd".EndsWith('d') |> equal true
testCase "String.StartsWith works" <| fun () ->
let args = [("ab", true); ("bc", false); ("cd", false); ("abcdx", false); ("abcd", true)]
for arg in args do
"abcd".StartsWith(fst arg)
|> equal (snd arg)
testCase "String.StartsWith with OrdinalIgnoreCase works" <| fun () ->
let args = [("ab", true); ("AB", true); ("BC", false); ("cd", false); ("abcdx", false); ("abcd", true)]
for arg in args do
"ABCD".StartsWith(fst arg, StringComparison.OrdinalIgnoreCase)
|> equal (snd arg)
testCase "String.StartsWith with ignoreCase boolean works" <| fun () ->
let args = [("ab", true); ("AB", true); ("BC", false); ("cd", false); ("abcdx", false); ("abcd", true)]
for arg in args do
"ABCD".StartsWith(fst arg, true, CultureInfo.InvariantCulture)
|> equal (snd arg)
testCase "String.EndsWith works" <| fun () ->
let args = [("ab", false); ("cd", true); ("bc", false); ("abcdx", false); ("abcd", true)]
for arg in args do
"abcd".EndsWith(fst arg)
|> equal (snd arg)
testCase "String.EndsWith with OrdinalIgnoreCase works" <| fun () ->
let args = [("ab", false); ("CD", true); ("cd", true); ("bc", false); ("xabcd", false); ("abcd", true)]
for arg in args do
"ABCD".EndsWith(fst arg, StringComparison.OrdinalIgnoreCase)
|> equal (snd arg)
testCase "String.EndsWith with ignoreCase boolean works" <| fun () ->
let args = [("ab", false); ("CD", true); ("cd", true); ("bc", false); ("xabcd", false); ("abcd", true)]
for arg in args do
"ABCD".EndsWith(fst arg, true, CultureInfo.InvariantCulture)
|> equal (snd arg)
testCase "String.Trim works" <| fun () ->
" abc ".Trim()
|> equal "abc"
testCase "String.Trim with chars works" <| fun () ->
@"\\\abc///".Trim('\\','/')
|> equal "abc"
testCase "String.Trim with special chars works" <| fun () ->
@"()[]{}abc/.?*+-^$|\".Trim(@"()[]{}/.?*+-^$|\".ToCharArray())
|> equal "abc"
testCase "String.TrimStart works" <| fun () ->
"!!--abc ".TrimStart('!','-')
|> equal "abc "
testCase "String.TrimStart with chars works" <| fun () ->
" abc ".TrimStart()
|> equal "abc "
testCase "String.TrimEnd works" <| fun () ->
" abc ".TrimEnd()
|> equal " abc"
testCase "String.TrimEnd with chars works" <| fun () ->
" abc??**".TrimEnd('*','?')
|> equal " abc"
@"\foo\bar\".Replace("\\", "/").TrimEnd('/')
|> equal "/foo/bar"
testCase "String.Empty works" <| fun () ->
let s = String.Empty
s |> equal ""
testCase "String.Chars works" <| fun () ->
let input = "hello"
input.Chars(2)
|> equal 'l'
testCase "String.Substring works" <| fun () ->
"abcdefg".Substring(2)
|> equal "cdefg"
testCase "String.Substring works with length" <| fun () ->
"abcdefg".Substring(2, 2)
|> equal "cd"
testCase "String.Substring throws error if startIndex or length are out of bounds" <| fun () -> // See #1955
let throws f =
try f () |> ignore; false
with _ -> true
throws (fun _ -> "abcdefg".Substring(20)) |> equal true
throws (fun _ -> "abcdefg".Substring(2, 10)) |> equal true
testCase "String.ToUpper works" <| fun () ->
"AbC".ToUpper() |> equal "ABC"
testCase "String.ToLower works" <| fun () ->
"aBc".ToLower() |> equal "abc"
testCase "String.ToUpperInvariant works" <| fun () ->
"AbC".ToUpperInvariant() |> equal "ABC"
testCase "String.ToLowerInvariant works" <| fun () ->
"aBc".ToLowerInvariant() |> equal "abc"
testCase "String.Length works" <| fun () ->
"AbC".Length |> equal 3
testCase "String item works" <| fun () ->
"AbC".[1] |> equal 'b'
testCase "String.ToCharArray works" <| fun () ->
let arr = "abcd".ToCharArray()
arr |> equal [|'a';'b';'c';'d'|]
testCase "String.ToCharArray with range works" <| fun () ->
let arr = "abcd".ToCharArray(1, 2)
arr |> equal [|'b';'c'|]
testCase "String enumeration handles surrogates pairs" <| fun () -> // See #1279
let unicodeString = ".\U0001f404."
unicodeString |> List.ofSeq |> Seq.length |> equal 4
String.length unicodeString |> equal 4
let mutable len = 0
for i in unicodeString do
len <- len + 1
equal 4 len