Commits

Anonymous committed 02422ca

ti_string (quoted) vs string_literal (unquoted)

  • Participants
  • Parent commits 171779c

Comments (0)

Files changed (2)

 value string_hash (a : string) = Hashtbl.hash a
 ;
 
-value ti_string : #tifull string =
+value ti_string_gen ~show =
   new tifull_on_tti
     ~cmp:string_cmp
     ~hash:string_hash
+    ~show
+    ti_string__base
+;
+
+value ti_string_literal : #tifull string =
+  ti_string_gen
     ~show:(fun s -> s)
-    ti_string__base
+;
+
+value ti_string : #tifull string =
+  ti_string_gen
+    ~show:(Printf.sprintf "%S")
 ;
 
 value int_cmp (a : int) b =
        (fun
         [ None -> ti_variant "None" [| |]
         | Some a -> ti_variant_dispatch "Some"
-            (fun [ "show" -> [| ubox ti_string "<hidden>" |]
+            (fun [ "show" -> [| ubox ti_string_literal "<hidden>" |]
                  | _ -> [| ubox ti_a a |]
                  ]
             )
 value cdt_test7 () =
   let test_data =
     [ ( { f_int = 123 ; f_string = "qwe" ; f_bool = True }
-      , "{ f_int = 123 ; f_string = qwe ; f_bool = True }"
+      , "{ f_int = 123 ; f_string = \"qwe\" ; f_bool = True }"
       )
     ]
   in
 
 value cdt_test8 () =
   let test_data =
-    [ ((None, "abc"), "(None, abc)")
-    ; ((Some 123, "def"), "(Some 123, def)")
+    [ ((None, "abc"), "(None, \"abc\")")
+    ; ((Some 123, "def"), "(Some 123, \"def\")")
     ]
   in
   List.iter