From 568fdb33de2a6a9b3f8d89d6418c37373d6c106e Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 23 Apr 2023 19:24:19 -0700 Subject: [PATCH 1/2] melange: delete dead code across the ext library --- jscomp/astlib/ast_attributes.ml | 2 +- jscomp/core/js_dump_lit.ml | 2 +- jscomp/{ext => core}/js_runtime_modules.ml | 0 jscomp/ext/bsb_db.mli | 66 ----- jscomp/ext/dune | 2 +- jscomp/ext/ext_array.ml | 87 ------- jscomp/ext/ext_array.mli | 14 - jscomp/ext/ext_filename.ml | 63 ----- jscomp/ext/ext_filename.mli | 13 - jscomp/ext/ext_ident.ml | 29 --- jscomp/ext/ext_ident.mli | 1 - jscomp/ext/ext_list.ml | 86 ------- jscomp/ext/ext_list.mli | 26 -- jscomp/ext/ext_path.ml | 21 -- jscomp/ext/ext_path.mli | 21 -- jscomp/ext/ext_pervasives.ml | 22 +- jscomp/ext/ext_pervasives.mli | 2 - jscomp/ext/ext_position.ml | 56 ---- jscomp/ext/ext_position.mli | 42 --- jscomp/ext/ext_string.cppo.ml | 286 --------------------- jscomp/ext/ext_string.cppo.mli | 108 -------- jscomp/ext/ext_string_array.ml | 87 ------- jscomp/ext/ext_string_array.mli | 27 -- jscomp/ext/ext_sys.ml | 7 +- jscomp/ext/ext_sys.mli | 5 +- jscomp/ext/ext_utf8.ml | 40 --- jscomp/ext/ext_utf8.mli | 9 +- jscomp/main/ounit_tests_main.ml | 2 - jscomp/ounit_tests/ounit_array_tests.ml | 40 --- jscomp/ounit_tests/ounit_list_test.ml | 15 -- jscomp/ounit_tests/ounit_path_tests.ml | 11 - jscomp/ounit_tests/ounit_string_tests.ml | 125 --------- jscomp/ounit_tests/ounit_utf8_test.ml | 32 --- jscomp/ounit_tests/ounit_util_tests.ml | 49 ---- 34 files changed, 11 insertions(+), 1387 deletions(-) rename jscomp/{ext => core}/js_runtime_modules.ml (100%) delete mode 100644 jscomp/ext/bsb_db.mli delete mode 100644 jscomp/ext/ext_position.ml delete mode 100644 jscomp/ext/ext_position.mli delete mode 100644 jscomp/ext/ext_string_array.ml delete mode 100644 jscomp/ext/ext_string_array.mli delete mode 100644 jscomp/ounit_tests/ounit_utf8_test.ml delete mode 100644 jscomp/ounit_tests/ounit_util_tests.ml diff --git a/jscomp/astlib/ast_attributes.ml b/jscomp/astlib/ast_attributes.ml index 673dd95016..91182bf907 100644 --- a/jscomp/astlib/ast_attributes.ml +++ b/jscomp/astlib/ast_attributes.ml @@ -160,7 +160,7 @@ let rs_externals (attrs : t) pval_prim = | _, _ -> Ext_list.exists attrs (fun { attr_name = { txt }; _ } -> Ext_string.starts_with txt "bs." - || Ext_array.exists external_attrs (fun (x : string) -> txt = x)) + || Array.exists (fun (x : string) -> txt = x) external_attrs) || prims_to_be_encoded pval_prim let is_inline : attr -> bool = diff --git a/jscomp/core/js_dump_lit.ml b/jscomp/core/js_dump_lit.ml index d6bbff6678..7f0fbfc02f 100644 --- a/jscomp/core/js_dump_lit.ml +++ b/jscomp/core/js_dump_lit.ml @@ -38,7 +38,7 @@ let rparen = ")" let exports = "exports" let dot = "." let comma = "," -let colon = Ext_string.single_colon +let colon = ":" let colon_space = ": " let throw = "throw" let default = "default" diff --git a/jscomp/ext/js_runtime_modules.ml b/jscomp/core/js_runtime_modules.ml similarity index 100% rename from jscomp/ext/js_runtime_modules.ml rename to jscomp/core/js_runtime_modules.ml diff --git a/jscomp/ext/bsb_db.mli b/jscomp/ext/bsb_db.mli deleted file mode 100644 index a2806b7ff5..0000000000 --- a/jscomp/ext/bsb_db.mli +++ /dev/null @@ -1,66 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(** Store a file called [.bsbuild] that can be communicated - between [bsb.exe] and [bsb_helper.exe]. - [bsb.exe] stores such data which would be retrieved by - [bsb_helper.exe]. It is currently used to combine with - ocamldep to figure out which module->file it depends on -*) - -type case = bool - -type info = - | Intf - (* intemediate state *) - | Impl - | Impl_intf - -type syntax_kind = Ml | Reason | Res -type 'a diff = Same of 'a | Different of { impl : 'a; intf : 'a } - -type module_info = { - mutable info : info; - dir : string diff; - syntax_kind : syntax_kind diff; - (* This is actually not stored in bsbuild meta info - since creating .d file only emit .cmj/.cmi dependencies, so it does not - need know which syntax it is written - *) - case : bool; - name_sans_extension : string; -} - -type map = module_info Map_string.t -type 'a cat = { mutable lib : 'a; mutable dev : 'a } -type t = map cat - -(** store the meta data indexed by {!Bsb_dir_index} - {[ - 0 --> lib group - 1 --> dev 1 group - . - - ]} -*) diff --git a/jscomp/ext/dune b/jscomp/ext/dune index 1602178b8d..ff49e4c2bb 100644 --- a/jscomp/ext/dune +++ b/jscomp/ext/dune @@ -6,7 +6,7 @@ (wrapped false) (flags (:standard -w -9 -open Melange_compiler_libs)) - (modules_without_implementation bsb_db ext_js_file_kind) + (modules_without_implementation ext_js_file_kind) (libraries unix melange-compiler-libs) (foreign_stubs (language c) diff --git a/jscomp/ext/ext_array.ml b/jscomp/ext/ext_array.ml index d007a981f8..8a0ede11a4 100644 --- a/jscomp/ext/ext_array.ml +++ b/jscomp/ext/ext_array.ml @@ -31,18 +31,6 @@ let reverse_range a i len = Array.unsafe_set a (i + len - 1 - k) t done -let reverse_in_place a = reverse_range a 0 (Array.length a) - -let reverse a = - let b_len = Array.length a in - if b_len = 0 then [||] - else - let b = Array.copy a in - for i = 0 to b_len - 1 do - Array.unsafe_set b i (Array.unsafe_get a (b_len - 1 - i)) - done; - b - let reverse_of_list = function | [] -> [||] | hd :: tl as l -> @@ -56,35 +44,6 @@ let reverse_of_list = function in fill 0 tl -let filter a f = - let arr_len = Array.length a in - let rec aux acc i = - if i = arr_len then reverse_of_list acc - else - let v = Array.unsafe_get a i in - if f v then aux (v :: acc) (i + 1) else aux acc (i + 1) - in - aux [] 0 - -let filter_map a (f : _ -> _ option) = - let arr_len = Array.length a in - let rec aux acc i = - if i = arr_len then reverse_of_list acc - else - let v = Array.unsafe_get a i in - match f v with Some v -> aux (v :: acc) (i + 1) | None -> aux acc (i + 1) - in - aux [] 0 - -let range from to_ = - if from > to_ then invalid_arg "Ext_array.range" - else Array.init (to_ - from + 1) (fun i -> i + from) - -let map2i f a b = - let len = Array.length a in - if len <> Array.length b then invalid_arg "Ext_array.map2i" - else Array.mapi (fun i a -> f i a (Array.unsafe_get b i)) a - let rec tolist_f_aux a f i res = if i < 0 then res else @@ -93,15 +52,6 @@ let rec tolist_f_aux a f i res = let to_list_f a f = tolist_f_aux a f (Array.length a - 1) [] -let rec tolist_aux a f i res = - if i < 0 then res - else - let v = Array.unsafe_get a i in - tolist_aux a f (i - 1) (match f v with Some v -> v :: res | None -> res) - -let to_list_map a f = tolist_aux a f (Array.length a - 1) [] -let to_list_map_acc a acc f = tolist_aux a f (Array.length a - 1) acc - let of_list_map a f = match a with | [] -> [||] @@ -171,40 +121,8 @@ let rfind_with_index arr cmp v = in aux (len - 1) -type 'a split = No_split | Split of 'a array * 'a array - -let find_with_index arr cmp v = - let len = Array.length arr in - let rec aux i len = - if i >= len then -1 - else if cmp (Array.unsafe_get arr i) v then i - else aux (i + 1) len - in - aux 0 len - -let find_and_split arr cmp v : _ split = - let i = find_with_index arr cmp v in - if i < 0 then No_split - else - Split (Array.sub arr 0 i, Array.sub arr (i + 1) (Array.length arr - i - 1)) - (** TODO: available since 4.03, use {!Array.exists} *) -let exists a p = - let n = Array.length a in - let rec loop i = - if i = n then false - else if p (Array.unsafe_get a i) then true - else loop (succ i) - in - loop 0 - -let rec unsafe_loop index len p xs ys = - if index >= len then true - else - p (Array.unsafe_get xs index) (Array.unsafe_get ys index) - && unsafe_loop (succ index) len p xs ys - let for_alli a p = let n = Array.length a in let rec loop i = @@ -214,11 +132,6 @@ let for_alli a p = in loop 0 -let for_all2_no_exn xs ys p = - let len_xs = Array.length xs in - let len_ys = Array.length ys in - len_xs = len_ys && unsafe_loop 0 len_xs p xs ys - let map a f = let open Array in let l = length a in diff --git a/jscomp/ext/ext_array.mli b/jscomp/ext/ext_array.mli index b7b6da7612..826cfe066e 100644 --- a/jscomp/ext/ext_array.mli +++ b/jscomp/ext/ext_array.mli @@ -25,24 +25,10 @@ val reverse_range : 'a array -> int -> int -> unit (** Some utilities for {!Array} operations *) -val reverse_in_place : 'a array -> unit -val reverse : 'a array -> 'a array val reverse_of_list : 'a list -> 'a array -val filter : 'a array -> ('a -> bool) -> 'a array -val filter_map : 'a array -> ('a -> 'b option) -> 'b array -val range : int -> int -> int array -val map2i : (int -> 'a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array val to_list_f : 'a array -> ('a -> 'b) -> 'b list -val to_list_map : 'a array -> ('a -> 'b option) -> 'b list -val to_list_map_acc : 'a array -> 'b list -> ('a -> 'b option) -> 'b list val of_list_map : 'a list -> ('a -> 'b) -> 'b array val rfind_with_index : 'a array -> ('a -> 'b -> bool) -> 'b -> int - -type 'a split = No_split | Split of 'a array * 'a array - -val find_and_split : 'a array -> ('a -> 'b -> bool) -> 'b -> 'a split -val exists : 'a array -> ('a -> bool) -> bool -val for_all2_no_exn : 'a array -> 'b array -> ('a -> 'b -> bool) -> bool val for_alli : 'a array -> (int -> 'a -> bool) -> bool val map : 'a array -> ('a -> 'b) -> 'b array val iter : 'a array -> ('a -> unit) -> unit diff --git a/jscomp/ext/ext_filename.ml b/jscomp/ext/ext_filename.ml index c5ecfd63b5..5aa7508fe7 100644 --- a/jscomp/ext/ext_filename.ml +++ b/jscomp/ext/ext_filename.ml @@ -26,24 +26,6 @@ let is_dir_sep_unix c = c = '/' let is_dir_sep_win_cygwin c = c = '/' || c = '\\' || c = ':' let is_dir_sep = if Sys.unix then is_dir_sep_unix else is_dir_sep_win_cygwin -(* reference ninja.cc IsKnownShellSafeCharacter *) -let shell_safe_character = function - | '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_' | '+' | '-' | '.' | '/' | '@' -> - true - | _ -> false - -let maybe_quote (s : string) = - let noneed_quote = Ext_string.for_all s shell_safe_character in - if noneed_quote then s else Filename.quote s - -let chop_extension_maybe name = - let rec search_dot i = - if i < 0 || is_dir_sep (String.unsafe_get name i) then name - else if String.unsafe_get name i = '.' then String.sub name 0 i - else search_dot (i - 1) - in - search_dot (String.length name - 1) - let get_extension_maybe name = let name_len = String.length name in let rec search_dot name i name_len = @@ -103,48 +85,3 @@ let module_name name = let name = Filename.basename name in let name_len = String.length name in search_dot (name_len - 1) name - -type module_info = { module_name : string; case : bool } - -let rec valid_module_name_aux name off len = - if off >= len then true - else - let c = String.unsafe_get name off in - match c with - | 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '\'' | '.' | '[' | ']' -> - valid_module_name_aux name (off + 1) len - | _ -> false - -type state = Invalid | Upper | Lower - -let valid_module_name name len = - if len = 0 then Invalid - else - let c = String.unsafe_get name 0 in - match c with - | 'A' .. 'Z' -> if valid_module_name_aux name 1 len then Upper else Invalid - | 'a' .. 'z' | '0' .. '9' | '_' | '[' | ']' -> - if valid_module_name_aux name 1 len then Lower else Invalid - | _ -> Invalid - -let as_module ~basename = - let rec search_dot i name name_len = - if i < 0 then - (* Input e.g, [a_b] *) - match valid_module_name name name_len with - | Invalid -> None - | Upper -> Some { module_name = name; case = true } - | Lower -> - Some { module_name = Ext_string.capitalize_ascii name; case = false } - else if String.unsafe_get name i = '.' then - (*Input e.g, [A_b] *) - match valid_module_name name i with - | Invalid -> None - | Upper -> - Some { module_name = Ext_string.capitalize_sub name i; case = true } - | Lower -> - Some { module_name = Ext_string.capitalize_sub name i; case = false } - else search_dot (i - 1) name name_len - in - let name_len = String.length basename in - search_dot (name_len - 1) basename name_len diff --git a/jscomp/ext/ext_filename.mli b/jscomp/ext/ext_filename.mli index 345ea754c8..dcc47dfa2c 100644 --- a/jscomp/ext/ext_filename.mli +++ b/jscomp/ext/ext_filename.mli @@ -27,15 +27,6 @@ library but rather specific to JS Module name convention. *) -(** An extension module to calculate relative path follow node/npm style. - TODO : this short name will have to change upon renaming the file. -*) - -val is_dir_sep : char -> bool -val shell_safe_character : char -> bool -val maybe_quote : string -> string -val chop_extension_maybe : string -> string - (* return an empty string if no extension found *) val get_extension_maybe : string -> string val get_all_extensions_maybe : string -> string option @@ -44,7 +35,3 @@ val chop_all_extensions_maybe : string -> string (* OCaml specific abstraction*) val module_name : string -> string - -type module_info = { module_name : string; case : bool } - -val as_module : basename:string -> module_info option diff --git a/jscomp/ext/ext_ident.ml b/jscomp/ext/ext_ident.ml index 026ad02972..4fc83870a5 100644 --- a/jscomp/ext/ext_ident.ml +++ b/jscomp/ext/ext_ident.ml @@ -72,34 +72,6 @@ let create = Ident.create_local (* FIXME: no need for `$' operator *) let create_tmp ?(name = Literals.tmp) () = create name -let js_module_table : Ident.t Hash_string.t = Hash_string.create 31 - -(* This is for a js exeternal module, we can change it when printing - for example - {[ - var React$1 = require('react'); - React$1.render(..) - ]} - - Given a name, if duplicated, they should have the same id -*) -(* let create_js_module (name : string) : Ident.t = - let name = - String.concat "" @@ Ext_list.map - (Ext_string.split name '-') Ext_string.capitalize_ascii in - (* TODO: if we do such transformation, we should avoid collision for example: - react-dom - react--dom - check collision later - *) - match Hash_string.find_exn js_module_table name with - | exception Not_found -> - let ans = Ident.create name in - (* let ans = { v with flags = js_module_flag} in *) - Hash_string.add js_module_table name ans; - ans - | v -> (* v *) Ident.rename v -*) let[@inline] convert ?(op = false) (c : char) : string = match c with @@ -174,7 +146,6 @@ let convert (name : string) = - other solution: use lazy values *) let make_unused () = create "_" -let reset () = Hash_string.clear js_module_table (* Has to be total order, [x < y] and [x > y] should be consistent diff --git a/jscomp/ext/ext_ident.mli b/jscomp/ext/ext_ident.mli index 07ede45eed..c8ab436e6d 100644 --- a/jscomp/ext/ext_ident.mli +++ b/jscomp/ext/ext_ident.mli @@ -31,7 +31,6 @@ val create_js : string -> Ident.t val create : string -> Ident.t val make_js_object : Ident.t -> Ident.t -val reset : unit -> unit val create_tmp : ?name:string -> unit -> Ident.t val make_unused : unit -> Ident.t val stamp : Ident.t -> int diff --git a/jscomp/ext/ext_list.ml b/jscomp/ext/ext_list.ml index 6cca63dc70..ff2090d46f 100644 --- a/jscomp/ext/ext_list.ml +++ b/jscomp/ext/ext_list.ml @@ -83,30 +83,6 @@ let combine_array arr l f = let len = Array.length arr in arr_list_combine_unsafe arr l 0 len [] f -let rec arr_list_filter_map_unasfe arr l i j acc f = - if i = j then acc - else - match l with - | [] -> invalid_arg "Ext_list.arr_list_filter_map_unsafe" - | h :: tl -> ( - match f arr.!(i) h with - | None -> arr_list_filter_map_unasfe arr tl (i + 1) j acc f - | Some v -> v :: arr_list_filter_map_unasfe arr tl (i + 1) j acc f) - -let array_list_filter_map arr l f = - let len = Array.length arr in - arr_list_filter_map_unasfe arr l 0 len [] f - -let rec map_split_opt (xs : 'a list) (f : 'a -> 'b option * 'c option) : - 'b list * 'c list = - match xs with - | [] -> ([], []) - | x :: xs -> ( - let c, d = f x in - let cs, ds = map_split_opt xs f in - ( (match c with Some c -> c :: cs | None -> cs), - match d with Some d -> d :: ds | None -> ds )) - let rec map_snd l f = match l with | [] -> [] @@ -275,41 +251,6 @@ let rec fold_right3 l r last acc f = (f a3 b3 c3 (f a4 b4 c4 (fold_right3 arest brest crest acc f))))) | _, _, _ -> invalid_arg "Ext_list.fold_right2" -let rec map2i l r f = - match (l, r) with - | [], [] -> [] - | [ a0 ], [ b0 ] -> [ f 0 a0 b0 ] - | [ a0; a1 ], [ b0; b1 ] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - [ c0; c1 ] - | [ a0; a1; a2 ], [ b0; b1; b2 ] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - [ c0; c1; c2 ] - | [ a0; a1; a2; a3 ], [ b0; b1; b2; b3 ] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - [ c0; c1; c2; c3 ] - | [ a0; a1; a2; a3; a4 ], [ b0; b1; b2; b3; b4 ] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - let c4 = f 4 a4 b4 in - [ c0; c1; c2; c3; c4 ] - | a0 :: a1 :: a2 :: a3 :: a4 :: arest, b0 :: b1 :: b2 :: b3 :: b4 :: brest -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - let c4 = f 4 a4 b4 in - c0 :: c1 :: c2 :: c3 :: c4 :: map2i arest brest f - | _, _ -> invalid_arg "Ext_list.map2" - let rec map2 l r f = match (l, r) with | [], [] -> [] @@ -462,15 +403,6 @@ let filter_mapi xs f = in aux 0 xs -let rec filter_map2 xs ys (f : 'a -> 'b -> 'c option) = - match (xs, ys) with - | [], [] -> [] - | u :: us, v :: vs -> ( - match f u v with - | None -> filter_map2 us vs f (* idea: rec f us vs instead? *) - | Some z -> z :: filter_map2 us vs f) - | _ -> invalid_arg "Ext_list.filter_map2" - let rec rev_map_append l1 l2 f = match l1 with [] -> l2 | a :: l -> rev_map_append l (f a :: l2) f @@ -492,7 +424,6 @@ let rec flat_map_aux f acc append lx = flat_map_aux f new_acc append rest let flat_map lx f = flat_map_aux f [] [] lx -let flat_map_append lx append f = flat_map_aux f [] append lx let rec length_compare l n = if n < 0 then `Gt @@ -527,12 +458,6 @@ and aux eq (x : 'a) (xss : 'a list list) : 'a list list = let stable_group lst eq = group eq lst |> rev -let rec drop h n = - if n < 0 then invalid_arg "Ext_list.drop" - else if n = 0 then h - else - match h with [] -> invalid_arg "Ext_list.drop" | _ :: tl -> drop tl (n - 1) - let rec find_first x p = match x with [] -> None | x :: l -> if p x then Some x else find_first l p @@ -714,17 +639,6 @@ let rec fold_left2 l1 l2 accu f = let singleton_exn xs = match xs with [ x ] -> x | _ -> assert false -let rec mem_string (xs : string list) (x : string) = - match xs with [] -> false | a :: l -> a = x || mem_string l x - -let group_by ~fk ~fv xs = - let tbl = Hash_string.create 64 in - iter xs (fun element -> - let key = fk element in - let value = fv element in - Hash_string.add_or_update tbl key ~update:(fun x -> value :: x) [ value ]); - tbl - let filter lst p = let rec find ~p accu lst = match lst with diff --git a/jscomp/ext/ext_list.mli b/jscomp/ext/ext_list.mli index 9e80c6a08a..5324520d7c 100644 --- a/jscomp/ext/ext_list.mli +++ b/jscomp/ext/ext_list.mli @@ -30,10 +30,6 @@ val combine_array_append : 'a array -> 'b list -> ('c * 'b) list -> ('a -> 'c) -> ('c * 'b) list val has_string : string list -> string -> bool - -val map_split_opt : - 'a list -> ('a -> 'b option * 'c option) -> 'b list * 'c list - val mapi : 'a list -> (int -> 'a -> 'b) -> 'b list val mapi_append : 'a list -> (int -> 'a -> 'b) -> 'b list -> 'b list val map_snd : ('a * 'b) list -> ('b -> 'c) -> ('a * 'c) list @@ -61,16 +57,11 @@ val fold_right3 : 'a list -> 'b list -> 'c list -> 'd -> ('a -> 'b -> 'c -> 'd -> 'd) -> 'd val map2 : 'a list -> 'b list -> ('a -> 'b -> 'c) -> 'c list -val map2i : 'a list -> 'b list -> (int -> 'a -> 'b -> 'c) -> 'c list val fold_left_with_offset : 'a list -> 'acc -> int -> ('a -> 'acc -> int -> 'acc) -> 'acc val filter_map : 'a list -> ('a -> 'b option) -> 'b list -(** @unused *) - -val exclude : 'a list -> ('a -> bool) -> 'a list -(** [exclude p l] is the opposite of [filter p l] *) val exclude_with_val : 'a list -> ('a -> bool) -> 'a list option (** [excludes p l] @@ -95,8 +86,6 @@ val split_at_last : 'a list -> 'a list * 'a *) val filter_mapi : 'a list -> ('a -> int -> 'b option) -> 'b list -val filter_map2 : 'a list -> 'b list -> ('a -> 'b -> 'c option) -> 'c list -val length_compare : 'a list -> int -> [ `Gt | `Eq | `Lt ] val length_ge : 'a list -> int -> bool (** @@ -117,7 +106,6 @@ val rev_map_append : 'a list -> 'b list -> ('a -> 'b) -> 'b list *) val flat_map : 'a list -> ('a -> 'b list) -> 'b list -val flat_map_append : 'a list -> 'b list -> ('a -> 'b list) -> 'b list val stable_group : 'a list -> ('a -> 'a -> bool) -> 'a list list (** @@ -135,12 +123,6 @@ val stable_group : 'a list -> ('a -> 'a -> bool) -> 'a list list which could be improved later *) -val drop : 'a list -> int -> 'a list -(** [drop n list] - raise when [n] is negative - raise when list's length is less than [n] -*) - val find_first : 'a list -> ('a -> bool) -> 'a option val find_first_exn : 'a list -> ('a -> bool) -> 'a @@ -195,12 +177,4 @@ val concat_append : 'a list list -> 'a list -> 'a list val fold_left2 : 'a list -> 'b list -> 'c -> ('a -> 'b -> 'c -> 'c) -> 'c val fold_left : 'a list -> 'b -> ('b -> 'a -> 'b) -> 'b val singleton_exn : 'a list -> 'a -val mem_string : string list -> string -> bool - -val group_by : - fk:('a -> string) -> fv:('a -> 'b) -> 'a list -> 'b list Hash_string.t - val filter : 'a list -> ('a -> bool) -> 'a list - -val array_list_filter_map : - 'a array -> 'b list -> ('a -> 'b -> 'c option) -> 'c list diff --git a/jscomp/ext/ext_path.ml b/jscomp/ext/ext_path.ml index 0f1d049893..3f5babe9e0 100644 --- a/jscomp/ext/ext_path.ml +++ b/jscomp/ext/ext_path.ml @@ -26,11 +26,6 @@ type t = (* | File of string *) | Dir of string [@@unboxed] -let simple_convert_node_path_to_os_path = - if Sys.unix then fun x -> x - else if Sys.win32 || Sys.cygwin then Ext_string.replace_slash_backward - else failwith ("Unknown OS : " ^ Sys.os_type) - let cwd = lazy (Sys.getcwd ()) let path_sep = if Sys.win32 then ';' else ':' @@ -268,19 +263,3 @@ let absolute_path cwd s = process s let absolute_cwd_path s = absolute_path cwd s - -(* let absolute cwd s = - match s with - | File x -> File (absolute_path cwd x ) - | Dir x -> Dir (absolute_path cwd x) *) - -let check_suffix_case = Ext_string.ends_with - -let real_path link_path = - match Unix.lstat link_path with - | { st_kind = S_LNK; _ } -> - let realpath = Unix.readlink link_path in - if Filename.is_relative realpath then - Filename.dirname link_path // realpath - else realpath - | _other -> link_path diff --git a/jscomp/ext/ext_path.mli b/jscomp/ext/ext_path.mli index 589646a06c..fa2235b58e 100644 --- a/jscomp/ext/ext_path.mli +++ b/jscomp/ext/ext_path.mli @@ -26,17 +26,6 @@ type t val path_sep : char -val simple_convert_node_path_to_os_path : string -> string -(** Js_output is node style, which means - separator is only '/' - - if the path contains 'node_modules', - [node_relative_path] will discard its prefix and - just treat it as a library instead -*) - -val split_by_sep_per_os : string -> string list - val combine : string -> string -> string (** [combine path1 path2] @@ -45,7 +34,6 @@ val combine : string -> string -> string *) val ( // ) : string -> string -> string -val strip_trailing_slashes : string -> string (** {[ @@ -72,12 +60,3 @@ val rel_normalized_absolute_path : from:string -> string -> string val normalize_absolute_path : string -> string val absolute_cwd_path : string -> string - -val concat : string -> string -> string -(** [concat dirname filename] - The same as {!Filename.concat} except a tiny optimization - for current directory simplification -*) - -val check_suffix_case : string -> string -> bool -val real_path : string -> string diff --git a/jscomp/ext/ext_pervasives.ml b/jscomp/ext/ext_pervasives.ml index dc9084e9e0..a3927f61db 100644 --- a/jscomp/ext/ext_pervasives.ml +++ b/jscomp/ext/ext_pervasives.ml @@ -1,5 +1,5 @@ (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,7 +17,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) @@ -67,21 +67,3 @@ let rec int_of_string_aux s acc off len = let nat_of_string_exn (s : string) = let acc = int_of_string_aux s 0 0 (String.length s) in if acc < 0 then invalid_arg s else acc - -(** return index *) -let parse_nat_of_string (s : string) (cursor : int ref) = - let current = !cursor in - assert (current >= 0); - let acc = ref 0 in - let s_len = String.length s in - let todo = ref true in - let cur = ref current in - while !todo && !cursor < s_len do - let d = Char.code (String.unsafe_get s !cur) - 48 in - if d >= 0 && d <= 9 then ( - acc := (10 * !acc) + d; - incr cur) - else todo := false - done; - cursor := !cur; - !acc diff --git a/jscomp/ext/ext_pervasives.mli b/jscomp/ext/ext_pervasives.mli index f96d959497..233d61bf9e 100644 --- a/jscomp/ext/ext_pervasives.mli +++ b/jscomp/ext/ext_pervasives.mli @@ -25,7 +25,6 @@ (** Extension to standard library [Pervavives] module, safe to open *) -external reraise : exn -> 'a = "%reraise" val finally : 'a -> clean:('a -> unit) -> ('a -> 'b) -> 'b (* val try_it : (unit -> 'a) -> unit *) @@ -42,4 +41,3 @@ val with_file_as_chan : string -> (out_channel -> 'a) -> 'a (* val todo : string -> 'a *) val nat_of_string_exn : string -> int -val parse_nat_of_string : string -> int ref -> int diff --git a/jscomp/ext/ext_position.ml b/jscomp/ext/ext_position.ml deleted file mode 100644 index 96e575bc66..0000000000 --- a/jscomp/ext/ext_position.ml +++ /dev/null @@ -1,56 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type t = Lexing.position = { - pos_fname : string; - pos_lnum : int; - pos_bol : int; - pos_cnum : int; -} - -let offset (x : t) (y : t) = - { - x with - pos_lnum = x.pos_lnum + y.pos_lnum - 1; - pos_cnum = x.pos_cnum + y.pos_cnum; - pos_bol = (if y.pos_lnum = 1 then x.pos_bol else x.pos_cnum + y.pos_bol); - } - -let print fmt (pos : t) = - Format.fprintf fmt "(line %d, column %d)" pos.pos_lnum - (pos.pos_cnum - pos.pos_bol) - -let lexbuf_from_channel_with_fname ic fname = - let x = Lexing.from_function (fun buf n -> input ic buf 0 n) in - let pos : t = - { - pos_fname = fname; - pos_lnum = 1; - pos_bol = 0; - pos_cnum = 0 (* copied from zero_pos*); - } - in - x.lex_start_p <- pos; - x.lex_curr_p <- pos; - x diff --git a/jscomp/ext/ext_position.mli b/jscomp/ext/ext_position.mli deleted file mode 100644 index 8ffcfd858d..0000000000 --- a/jscomp/ext/ext_position.mli +++ /dev/null @@ -1,42 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type t = Lexing.position = { - pos_fname : string; - pos_lnum : int; - pos_bol : int; - pos_cnum : int; -} - -val offset : t -> t -> t -(** [offset pos newpos] - return a new position - here [newpos] is zero based, the use case is that - at position [pos], we get a string and Lexing from that string, - therefore, we get a [newpos] and we need rebase it on top of - [pos] -*) - -val lexbuf_from_channel_with_fname : in_channel -> string -> Lexing.lexbuf -val print : Format.formatter -> t -> unit diff --git a/jscomp/ext/ext_string.cppo.ml b/jscomp/ext/ext_string.cppo.ml index 061c76a1df..88fcb9c0e0 100644 --- a/jscomp/ext/ext_string.cppo.ml +++ b/jscomp/ext/ext_string.cppo.ml @@ -22,12 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - - - - - - (* {[ split " test_unsafe_obj_ffi_ppx.cmi" ~keep_empty:false ' ']} *) @@ -52,30 +46,10 @@ let split_by ?(keep_empty=false) is_delim str = in loop [] len (len - 1) -let trim s = - let i = ref 0 in - let j = String.length s in - while !i < j && - let u = String.unsafe_get s !i in - u = '\t' || u = '\n' || u = ' ' - do - incr i; - done; - let k = ref (j - 1) in - while !k >= !i && - let u = String.unsafe_get s !k in - u = '\t' || u = '\n' || u = ' ' do - decr k ; - done; - String.sub s !i (!k - !i + 1) - let split ?keep_empty str on = if str = "" then [] else split_by ?keep_empty (fun x -> (x : char) = on) str ;; -let quick_split_by_ws str : string list = - split_by ~keep_empty:false (fun x -> x = '\t' || x = '\n' || x = ' ') str - let starts_with s beg = let beg_len = String.length beg in let s_len = String.length s in @@ -156,17 +130,6 @@ let for_all s (p : char -> bool) = let is_empty s = String.length s = 0 -let repeat n s = - let len = String.length s in - let res = Bytes.create(n * len) in - for i = 0 to pred n do - String.blit s 0 res (i * len) len - done; - Bytes.to_string res - - - - let unsafe_is_sub ~sub i s j ~len = let rec check k = if k = len @@ -179,37 +142,6 @@ let unsafe_is_sub ~sub i s j ~len = -let find ?(start=0) ~sub s = - let exception Local_exit in - let n = String.length sub in - let s_len = String.length s in - let i = ref start in - try - while !i + n <= s_len do - if unsafe_is_sub ~sub 0 s !i ~len:n then - raise_notrace Local_exit; - incr i - done; - -1 - with Local_exit -> - !i - -let contain_substring s sub = - find s ~sub >= 0 - -(** TODO: optimize - avoid nonterminating when string is empty -*) -let non_overlap_count ~sub s = - let sub_len = String.length sub in - let rec aux acc off = - let i = find ~start:off ~sub s in - if i < 0 then acc - else aux (acc + 1) (i + sub_len) in - if String.length sub = 0 then invalid_arg "Ext_string.non_overlap_count" - else aux 0 0 - - let rfind ~sub s = let exception Local_exit in let n = String.length sub in @@ -231,93 +163,18 @@ let tail_from s x = let equal (x : string) y = x = y -(* let rec index_rec s lim i c = - if i >= lim then -1 else - if String.unsafe_get s i = c then i - else index_rec s lim (i + 1) c *) - - - -let rec index_rec_count s lim i c count = - if i >= lim then -1 else - if String.unsafe_get s i = c then - if count = 1 then i - else index_rec_count s lim (i + 1) c (count - 1) - else index_rec_count s lim (i + 1) c count - -let index_count s i c count = - let lim = String.length s in - if i < 0 || i >= lim || count < 1 then - invalid_arg ("index_count: ( " ^string_of_int i ^ "," ^string_of_int count ^ ")" ); - index_rec_count s lim i c count - -(* let index_next s i c = - index_count s i c 1 *) - -(* let extract_until s cursor c = - let len = String.length s in - let start = !cursor in - if start < 0 || start >= len then ( - cursor := -1; - "" - ) - else - let i = index_rec s len start c in - let finish = - if i < 0 then ( - cursor := -1 ; - len - ) - else ( - cursor := i + 1; - i - ) in - String.sub s start (finish - start) *) - let rec rindex_rec s i c = if i < 0 then i else if String.unsafe_get s i = c then i else rindex_rec s (i - 1) c;; -let rec rindex_rec_opt s i c = - if i < 0 then None else - if String.unsafe_get s i = c then Some i else rindex_rec_opt s (i - 1) c;; - let rindex_neg s c = rindex_rec s (String.length s - 1) c;; -let rindex_opt s c = - rindex_rec_opt s (String.length s - 1) c;; - - (** TODO: can be improved to return a positive integer instead *) let rec unsafe_no_char x ch i last_idx = i > last_idx || (String.unsafe_get x i <> ch && unsafe_no_char x ch (i + 1) last_idx) -let rec unsafe_no_char_idx x ch i last_idx = - if i > last_idx then -1 - else - if String.unsafe_get x i <> ch then - unsafe_no_char_idx x ch (i + 1) last_idx - else i - -let no_char x ch i len : bool = - let str_len = String.length x in - if i < 0 || i >= str_len || len >= str_len then invalid_arg "Ext_string.no_char" - else unsafe_no_char x ch i len - - -let no_slash x = - unsafe_no_char x '/' 0 (String.length x - 1) - -let no_slash_idx x = - unsafe_no_char_idx x '/' 0 (String.length x - 1) - -let no_slash_idx_from x from = - let last_idx = String.length x - 1 in - assert (from >= 0); - unsafe_no_char_idx x '/' from last_idx - let replace_slash_backward (x : string ) = let len = String.length x in if unsafe_no_char x '/' 0 (len - 1) then x @@ -341,96 +198,6 @@ let compare = Bs_hash_stubs.string_length_based_compare #else external compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; #endif -let single_space = " " -let single_colon = ":" - -let concat_array sep (s : string array) = - let s_len = Array.length s in - match s_len with - | 0 -> empty - | 1 -> Array.unsafe_get s 0 - | _ -> - let sep_len = String.length sep in - let len = ref 0 in - for i = 0 to s_len - 1 do - len := !len + String.length (Array.unsafe_get s i) - done; - let target = - Bytes.create - (!len + (s_len - 1) * sep_len ) in - let hd = (Array.unsafe_get s 0) in - let hd_len = String.length hd in - String.unsafe_blit hd 0 target 0 hd_len; - let current_offset = ref hd_len in - for i = 1 to s_len - 1 do - String.unsafe_blit sep 0 target !current_offset sep_len; - let cur = Array.unsafe_get s i in - let cur_len = String.length cur in - let new_off_set = (!current_offset + sep_len ) in - String.unsafe_blit cur 0 target new_off_set cur_len; - current_offset := - new_off_set + cur_len ; - done; - Bytes.unsafe_to_string target - -let concat3 a b c = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let len = a_len + b_len + c_len in - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - Bytes.unsafe_to_string target - -let concat4 a b c d = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let d_len = String.length d in - let len = a_len + b_len + c_len + d_len in - - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - String.unsafe_blit d 0 target (a_len + b_len + c_len) d_len; - Bytes.unsafe_to_string target - - -let concat5 a b c d e = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let d_len = String.length d in - let e_len = String.length e in - let len = a_len + b_len + c_len + d_len + e_len in - - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - String.unsafe_blit d 0 target (a_len + b_len + c_len) d_len; - String.unsafe_blit e 0 target (a_len + b_len + c_len + d_len) e_len; - Bytes.unsafe_to_string target - - - -let inter2 a b = - concat3 a single_space b - - -let inter3 a b c = - concat5 a single_space b single_space c - - - - - -let inter4 a b c d = - concat_array single_space [| a; b ; c; d|] - let parent_dir_lit = ".." let current_dir_lit = "." @@ -471,64 +238,11 @@ let capitalize_sub (s : string) len : string = done ; Bytes.unsafe_to_string bytes - - let uncapitalize_ascii = String.uncapitalize_ascii let lowercase_ascii = String.lowercase_ascii - -external (.![]) : string -> int -> int = "%string_unsafe_get" - -let get_int_1 (x : string) off : int = - Char.code x.[off] - -let get_int_2 (x : string) off : int = - Char.code x.[off] lor - Char.code x.[off+1] lsl 8 - -let get_int_3 (x : string) off : int = - Char.code x.[off] lor - Char.code x.[off+1] lsl 8 lor - Char.code x.[off+2] lsl 16 - -let get_int_4 (x : string) off : int = - Char.code x.[off] lor - Char.code x.[off+1] lsl 8 lor - Char.code x.[off+2] lsl 16 lor - Char.code x.[off+3] lsl 24 - -let get_1_2_3_4 (x : string) ~off len : int = - if len = 1 then get_int_1 x off - else if len = 2 then get_int_2 x off - else if len = 3 then get_int_3 x off - else if len = 4 then get_int_4 x off - else assert false - -let unsafe_sub x offs len = - let b = Bytes.create len in - Bytes.unsafe_blit_string x offs b 0 len; - (Bytes.unsafe_to_string b) - -let is_valid_hash_number (x:string) = - let len = String.length x in - len > 0 && ( - let a = x.![0] in - a <= 57 && - (if len > 1 then - a > 48 && - for_all_from x 1 (function '0' .. '9' -> true | _ -> false) - else - a >= 48 ) - ) - - -let hash_number_as_i32_exn - ( x : string) : int32 = - Int32.of_string x - - let first_marshal_char (x : string) = x <> "" && ( String.unsafe_get x 0 = '\132') diff --git a/jscomp/ext/ext_string.cppo.mli b/jscomp/ext/ext_string.cppo.mli index d20ced56dc..e2b51190aa 100644 --- a/jscomp/ext/ext_string.cppo.mli +++ b/jscomp/ext/ext_string.cppo.mli @@ -22,13 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - - - - - - - (** Extension to the standard library [String] module, fixed some bugs like avoiding locale sensitivity *) @@ -36,26 +29,11 @@ val split_by : ?keep_empty:bool -> (char -> bool) -> string -> string list -(** remove whitespace letters ('\t', '\n', ' ') on both side*) -val trim : string -> string - - (** default is false *) val split : ?keep_empty:bool -> string -> char -> string list -(** split by space chars for quick scripting *) -val quick_split_by_ws : string -> string list - - - val starts_with : string -> string -> bool -(** - return [-1] when not found, the returned index is useful - see [ends_with_then_chop] -*) -val ends_with_index : string -> string -> int - val ends_with : string -> string -> bool val ends_with_char : string -> char -> bool @@ -91,48 +69,8 @@ val for_all : val is_empty : string -> bool -val repeat : int -> string -> string - val equal : string -> string -> bool -(** - [extract_until s cursor sep] - When [sep] not found, the cursor is updated to -1, - otherwise cursor is increased to 1 + [sep_position] - User can not determine whether it is found or not by - telling the return string is empty since - "\n\n" would result in an empty string too. -*) -(* val extract_until: - string -> - int ref -> (* cursor to be updated *) - char -> - string *) - -val index_count: - string -> - int -> - char -> - int -> - int - -(* val index_next : - string -> - int -> - char -> - int *) - - -(** - [find ~start ~sub s] - returns [-1] if not found -*) -val find : ?start:int -> sub:string -> string -> int - -val contain_substring : string -> string -> bool - -val non_overlap_count : sub:string -> string -> int - val rfind : sub:string -> string -> int (** [tail_from s 1] @@ -144,19 +82,6 @@ val tail_from : string -> int -> string (** returns negative number if not found *) val rindex_neg : string -> char -> int -val rindex_opt : string -> char -> int option - - -val no_char : string -> char -> int -> int -> bool - - -val no_slash : string -> bool - -(** return negative means no slash, otherwise [i] means the place for first slash *) -val no_slash_idx : string -> int - -val no_slash_idx_from : string -> int -> int - (** if no conversion happens, reference equality holds *) val replace_slash_backward : string -> string @@ -170,17 +95,6 @@ val compare : string -> string -> int #else external compare : string -> string -> int = "caml_string_length_based_compare" [@@noalloc];; #endif -val single_space : string - -val concat3 : string -> string -> string -> string -val concat4 : string -> string -> string -> string -> string -val concat5 : string -> string -> string -> string -> string -> string -val inter2 : string -> string -> string -val inter3 : string -> string -> string -> string -val inter4 : string -> string -> string -> string -> string -val concat_array : string -> string array -> string - -val single_colon : string val parent_dir_lit : string val current_dir_lit : string @@ -196,30 +110,8 @@ val uncapitalize_ascii : string -> string val lowercase_ascii : string -> string -(** Play parity to {!Ext_buffer.add_int_1} *) -val get_int_1 : string -> int -> int -val get_int_2 : string -> int -> int -val get_int_3 : string -> int -> int -val get_int_4 : string -> int -> int - -val get_1_2_3_4 : - string -> - off:int -> - int -> - int - -val unsafe_sub : - string -> - int -> - int -> - string - val first_marshal_char: string -> bool -val is_valid_hash_number: string -> bool - -val hash_number_as_i32_exn: string -> int32 - val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a diff --git a/jscomp/ext/ext_string_array.ml b/jscomp/ext/ext_string_array.ml deleted file mode 100644 index 27b8c182d4..0000000000 --- a/jscomp/ext/ext_string_array.ml +++ /dev/null @@ -1,87 +0,0 @@ -(* Copyright (C) 2020 - Present Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(* Invariant: the same as encoding Map_string.compare_key *) -let cmp = Ext_string.compare - -let rec binarySearchAux (arr : string array) (lo : int) (hi : int) - (key : string) : _ option = - let mid = (lo + hi) / 2 in - let midVal = Array.unsafe_get arr mid in - let c = cmp key midVal in - if c = 0 then Some mid - else if c < 0 then - (* a[lo] =< key < a[mid] <= a[hi] *) - if hi = mid then - let loVal = Array.unsafe_get arr lo in - if loVal = key then Some lo else None - else binarySearchAux arr lo mid key - else if (* a[lo] =< a[mid] < key <= a[hi] *) - lo = mid then - let hiVal = Array.unsafe_get arr hi in - if hiVal = key then Some hi else None - else binarySearchAux arr mid hi key - -let find_sorted sorted key : int option = - let len = Array.length sorted in - if len = 0 then None - else - let lo = Array.unsafe_get sorted 0 in - let c = cmp key lo in - if c < 0 then None - else - let hi = Array.unsafe_get sorted (len - 1) in - let c2 = cmp key hi in - if c2 > 0 then None else binarySearchAux sorted 0 (len - 1) key - -let rec binarySearchAssoc (arr : (string * _) array) (lo : int) (hi : int) - (key : string) : _ option = - let mid = (lo + hi) / 2 in - let midVal = Array.unsafe_get arr mid in - let c = cmp key (fst midVal) in - if c = 0 then Some (snd midVal) - else if c < 0 then - (* a[lo] =< key < a[mid] <= a[hi] *) - if hi = mid then - let loVal = Array.unsafe_get arr lo in - if fst loVal = key then Some (snd loVal) else None - else binarySearchAssoc arr lo mid key - else if (* a[lo] =< a[mid] < key <= a[hi] *) - lo = mid then - let hiVal = Array.unsafe_get arr hi in - if fst hiVal = key then Some (snd hiVal) else None - else binarySearchAssoc arr mid hi key - -let find_sorted_assoc (type a) (sorted : (string * a) array) (key : string) : - a option = - let len = Array.length sorted in - if len = 0 then None - else - let lo = Array.unsafe_get sorted 0 in - let c = cmp key (fst lo) in - if c < 0 then None - else - let hi = Array.unsafe_get sorted (len - 1) in - let c2 = cmp key (fst hi) in - if c2 > 0 then None else binarySearchAssoc sorted 0 (len - 1) key diff --git a/jscomp/ext/ext_string_array.mli b/jscomp/ext/ext_string_array.mli deleted file mode 100644 index 10df713249..0000000000 --- a/jscomp/ext/ext_string_array.mli +++ /dev/null @@ -1,27 +0,0 @@ -(* Copyright (C) 2020 - Present Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -val cmp : string -> string -> int -val find_sorted : string array -> string -> int option -val find_sorted_assoc : (string * 'a) array -> string -> 'a option diff --git a/jscomp/ext/ext_sys.ml b/jscomp/ext/ext_sys.ml index af7ff97e5d..fbd3795b60 100644 --- a/jscomp/ext/ext_sys.ml +++ b/jscomp/ext/ext_sys.ml @@ -1,5 +1,5 @@ (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,12 +17,9 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** TODO: not exported yet, wait for Windows Fix*) -let is_directory_no_exn f = try Sys.is_directory f with _ -> false - let is_windows_or_cygwin = Sys.win32 || Sys.cygwin diff --git a/jscomp/ext/ext_sys.mli b/jscomp/ext/ext_sys.mli index 1bb4f0aabd..3dda45f85a 100644 --- a/jscomp/ext/ext_sys.mli +++ b/jscomp/ext/ext_sys.mli @@ -1,5 +1,5 @@ (* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,10 +17,9 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val is_directory_no_exn : string -> bool val is_windows_or_cygwin : bool diff --git a/jscomp/ext/ext_utf8.ml b/jscomp/ext/ext_utf8.ml index 281bfb7a0c..cf79e6bb86 100644 --- a/jscomp/ext/ext_utf8.ml +++ b/jscomp/ext/ext_utf8.ml @@ -44,19 +44,6 @@ let classify chr = (* c 0b1111_110__ *) else Invalid -exception Invalid_utf8 of string - -(* when the first char is [Leading], - TODO: need more error checking - when out of bond -*) -let rec follow s n (c : int) offset = - if n = 0 then (c, offset) - else - match classify s.[offset + 1] with - | Cont cc -> follow s (n - 1) ((c lsl 6) lor (cc land 0x3f)) (offset + 1) - | _ -> raise (Invalid_utf8 "Continuation byte expected") - let rec next s ~remaining offset = if remaining = 0 then offset else @@ -65,30 +52,3 @@ let rec next s ~remaining offset = | _ -> -1 | exception _ -> -1 (* it can happen when out of bound *) - -let decode_utf8_string s = - let lst = ref [] in - let add elem = lst := elem :: !lst in - let rec decode_utf8_cont s i s_len = - if i = s_len then () - else - match classify s.[i] with - | Single c -> - add c; - decode_utf8_cont s (i + 1) s_len - | Cont _ -> raise (Invalid_utf8 "Unexpected continuation byte") - | Leading (n, c) -> - let c', i' = follow s n c i in - add c'; - decode_utf8_cont s (i' + 1) s_len - | Invalid -> raise (Invalid_utf8 "Invalid byte") - in - decode_utf8_cont s 0 (String.length s); - List.rev !lst - -(** To decode {j||j} we need verify in the ast so that we have better error - location, then we do the decode later -*) - -(* let verify s loc = - assert false *) diff --git a/jscomp/ext/ext_utf8.mli b/jscomp/ext/ext_utf8.mli index 0e1614e965..5ce4a466fd 100644 --- a/jscomp/ext/ext_utf8.mli +++ b/jscomp/ext/ext_utf8.mli @@ -25,13 +25,8 @@ type byte = Single of int | Cont of int | Leading of int * int | Invalid val classify : char -> byte -val follow : string -> int -> int -> int -> int * int val next : string -> remaining:int -> int -> int -(** - return [-1] if failed +(** + return [-1] if failed *) - -exception Invalid_utf8 of string - -val decode_utf8_string : string -> int list diff --git a/jscomp/main/ounit_tests_main.ml b/jscomp/main/ounit_tests_main.ml index 7b5e1596f1..7786d48f19 100644 --- a/jscomp/main/ounit_tests_main.ml +++ b/jscomp/main/ounit_tests_main.ml @@ -36,10 +36,8 @@ let suites = Ounit_string_tests.suites; Ounit_int_vec_tests.suites; Ounit_ident_mask_tests.suites; - Ounit_utf8_test.suites; Ounit_unicode_tests.suites; Ounit_depends_format_test.suites; - Ounit_util_tests.suites; ] let _ = OUnit.run_test_tt_main suites diff --git a/jscomp/ounit_tests/ounit_array_tests.ml b/jscomp/ounit_tests/ounit_array_tests.ml index 2b3a34f972..af394a604e 100644 --- a/jscomp/ounit_tests/ounit_array_tests.ml +++ b/jscomp/ounit_tests/ounit_array_tests.ml @@ -7,26 +7,6 @@ let printer_int_array xs = let suites = __FILE__ >::: [ - ( __LOC__ >:: fun _ -> - Ext_array.find_and_split [| "a"; "b"; "c" |] Ext_string.equal "--" - =~ No_split ); - ( __LOC__ >:: fun _ -> - Ext_array.find_and_split [| "a"; "b"; "c"; "--" |] Ext_string.equal - "--" - =~ Split ([| "a"; "b"; "c" |], [||]) ); - ( __LOC__ >:: fun _ -> - Ext_array.find_and_split - [| "--"; "a"; "b"; "c"; "--" |] - Ext_string.equal "--" - =~ Split ([||], [| "a"; "b"; "c"; "--" |]) ); - ( __LOC__ >:: fun _ -> - Ext_array.find_and_split - [| "u"; "g"; "--"; "a"; "b"; "c"; "--" |] - Ext_string.equal "--" - =~ Split ([| "u"; "g" |], [| "a"; "b"; "c"; "--" |]) ); - ( __LOC__ >:: fun _ -> - Ext_array.reverse [| 1; 2 |] =~ [| 2; 1 |]; - Ext_array.reverse [||] =~ [||] ); ( __LOC__ >:: fun _ -> let ( =~ ) = OUnit.assert_equal ~printer:printer_int_array in let k x y = Ext_array.of_list_map y x in @@ -37,24 +17,4 @@ let suites = k succ [ 1; 2; 3; 4; 5 ] =~ [| 2; 3; 4; 5; 6 |]; k succ [ 1; 2; 3; 4; 5; 6 ] =~ [| 2; 3; 4; 5; 6; 7 |]; k succ [ 1; 2; 3; 4; 5; 6; 7 ] =~ [| 2; 3; 4; 5; 6; 7; 8 |] ); - ( __LOC__ >:: fun _ -> - Ext_array.to_list_map_acc [| 1; 2; 3; 4; 5; 6 |] [ 1; 2; 3 ] - (fun x -> if x mod 2 = 0 then Some x else None) - =~ [ 2; 4; 6; 1; 2; 3 ] ); - ( __LOC__ >:: fun _ -> - Ext_array.to_list_map_acc [| 1; 2; 3; 4; 5; 6 |] [] (fun x -> - if x mod 2 = 0 then Some x else None) - =~ [ 2; 4; 6 ] ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ - (Ext_array.for_all2_no_exn [| 1; 2; 3 |] [| 1; 2; 3 |] ( = )) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ (Ext_array.for_all2_no_exn [||] [||] ( = )); - OUnit.assert_bool __LOC__ - (not @@ Ext_array.for_all2_no_exn [||] [| 1 |] ( = )) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ - (not - (Ext_array.for_all2_no_exn [| 1; 2; 3 |] [| 1; 2; 33 |] ( = ))) - ); ] diff --git a/jscomp/ounit_tests/ounit_list_test.ml b/jscomp/ounit_tests/ounit_list_test.ml index a94cc9facc..bd16d14417 100644 --- a/jscomp/ounit_tests/ounit_list_test.ml +++ b/jscomp/ounit_tests/ounit_list_test.ml @@ -13,10 +13,6 @@ let suites = OUnit.assert_equal (Ext_list.flat_map [ 1; 2 ] (fun x -> [ x; x ])) [ 1; 1; 2; 2 ] ); - ( __LOC__ >:: fun _ -> - OUnit.assert_equal - (Ext_list.flat_map_append [ 1; 2 ] [ 3; 4 ] (fun x -> [ x; x ])) - [ 1; 1; 2; 2; 3; 4 ] ); ( __LOC__ >:: fun _ -> let ( =~ ) = OUnit.assert_equal ~printer:printer_int_list in Ext_list.flat_map [] (fun x -> [ succ x ]) =~ []; @@ -40,11 +36,6 @@ let suites = Ext_list.map_last [ 0; 0; 0; 0; 0; 0 ] f =~ [ 0; 0; 0; 0; 0; 1 ]; Ext_list.map_last [ 0; 0; 0; 0; 0; 0; 0 ] f =~ [ 0; 0; 0; 0; 0; 0; 1 ] ); - ( __LOC__ >:: fun _ -> - OUnit.assert_equal - (Ext_list.flat_map_append [ 1; 2 ] [ false; false ] (fun x -> - if x mod 2 = 0 then [ true ] else [])) - [ true; false; false ] ); ( __LOC__ >:: fun _ -> OUnit.assert_equal (Ext_list.map_append [ 0; 1; 2 ] [ "1"; "2"; "3" ] (fun x -> @@ -79,12 +70,6 @@ let suites = ignore @@ Ext_list.assoc_by_int [ (2, "x"); (3, "y"); (1, "z") ] 11 None) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_equal (Ext_list.length_compare [ 0; 0; 0 ] 3) `Eq; - OUnit.assert_equal (Ext_list.length_compare [ 0; 0; 0 ] 1) `Gt; - OUnit.assert_equal (Ext_list.length_compare [ 0; 0; 0 ] 4) `Lt; - OUnit.assert_equal (Ext_list.length_compare [] (-1)) `Gt; - OUnit.assert_equal (Ext_list.length_compare [] 0) `Eq ); ( __LOC__ >:: fun _ -> OUnit.assert_bool __LOC__ (Ext_list.length_larger_than_n [ 1; 2 ] [ 1 ] 1); diff --git a/jscomp/ounit_tests/ounit_path_tests.ml b/jscomp/ounit_tests/ounit_path_tests.ml index 4a02b1d6ab..0565385318 100644 --- a/jscomp/ounit_tests/ounit_path_tests.ml +++ b/jscomp/ounit_tests/ounit_path_tests.ml @@ -124,15 +124,4 @@ let suites = Ext_path.node_rebase_file ~to_:"lib/js/src/a/" ~from:"lib/js/src/a/" "b" =~ "./b" ); - ( __LOC__ >:: fun _ -> - Ext_path.strip_trailing_slashes "hello" =~ "hello"; - Ext_path.strip_trailing_slashes "hello/" =~ "hello"; - Ext_path.strip_trailing_slashes "hello///" =~ "hello"; - Ext_path.strip_trailing_slashes "///" =~ "/"; - Ext_path.strip_trailing_slashes "/" =~ "/" ); - ( __LOC__ >:: fun _ -> - Ext_path.concat "/foo" "./bar" - |> Ext_path.normalize_absolute_path =~ "/foo/bar"; - Ext_path.concat "foo" "./bar" - |> Ext_path.normalize_absolute_path =~ "./foo/bar" ); ] diff --git a/jscomp/ounit_tests/ounit_string_tests.ml b/jscomp/ounit_tests/ounit_string_tests.ml index 4f32302233..c427530cc5 100644 --- a/jscomp/ounit_tests/ounit_string_tests.ml +++ b/jscomp/ounit_tests/ounit_string_tests.ml @@ -38,14 +38,6 @@ let suites = nl cur b =~ "" ; nl cur b =~ "" ; end ; *) - ( __LOC__ >:: fun _ -> - let b = "a\nb\nc\nd\n" in - let a = Ext_string.index_count in - a b 0 '\n' 1 =~ 1; - a b 0 '\n' 2 =~ 3; - a b 0 '\n' 3 =~ 5; - a b 0 '\n' 4 =~ 7; - a b 0 '\n' 5 =~ -1 ); ( __LOC__ >:: fun _ -> OUnit.assert_bool "empty string" (Ext_string.rindex_neg "" 'x' < 0) ); @@ -77,40 +69,6 @@ let suites = ; "-.ml" ] end; *) - ( __LOC__ >:: fun _ -> - Ext_filename.module_name "a/hello.ml" =~ "Hello"; - Ext_filename.as_module ~basename:"a.ml" - =~ Some { module_name = "A"; case = false }; - Ext_filename.as_module ~basename:"Aa.ml" - =~ Some { module_name = "Aa"; case = true }; - (* Ext_filename.as_module ~basename:"_Aa.ml" =~ None; *) - Ext_filename.as_module ~basename:"A_a" - =~ Some { module_name = "A_a"; case = true }; - Ext_filename.as_module ~basename:"" =~ None; - Ext_filename.as_module ~basename:"a/hello.ml" =~ None ); - ( __LOC__ >:: fun _ -> - Ext_string.find ~sub:"hello" "xx hello xx" =~ 3; - Ext_string.rfind ~sub:"hello" "xx hello xx" =~ 3; - Ext_string.find ~sub:"hello" "xx hello hello xx" =~ 3; - Ext_string.rfind ~sub:"hello" "xx hello hello xx" =~ 9 ); - ( __LOC__ >:: fun _ -> - Ext_string.non_overlap_count ~sub:"0" "1000,000" =~ 6; - Ext_string.non_overlap_count ~sub:"0" "000000" =~ 6; - Ext_string.non_overlap_count ~sub:"00" "000000" =~ 3; - Ext_string.non_overlap_count ~sub:"00" "00000" =~ 2 ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ (Ext_string.contain_substring "abc" "abc"); - OUnit.assert_bool __LOC__ (Ext_string.contain_substring "abc" "a"); - OUnit.assert_bool __LOC__ (Ext_string.contain_substring "abc" "b"); - OUnit.assert_bool __LOC__ (Ext_string.contain_substring "abc" "c"); - OUnit.assert_bool __LOC__ (Ext_string.contain_substring "abc" ""); - OUnit.assert_bool __LOC__ - (not @@ Ext_string.contain_substring "abc" "abcc") ); - ( __LOC__ >:: fun _ -> - Ext_string.trim " \t\n" =~ ""; - Ext_string.trim " \t\nb" =~ "b"; - Ext_string.trim "b \t\n" =~ "b"; - Ext_string.trim "\t\n b \t\n" =~ "b" ); ( __LOC__ >:: fun _ -> Ext_string.starts_with "ab" "a" =~ true; Ext_string.starts_with "ab" "" =~ true; @@ -161,12 +119,6 @@ let suites = OUnit.assert_bool __LOC__ (let old = "a:bd" in Ext_string.replace_backward_slash old == old) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ (Ext_string.no_slash "ahgoh"); - OUnit.assert_bool __LOC__ (Ext_string.no_slash ""); - OUnit.assert_bool __LOC__ (not (Ext_string.no_slash "ahgoh/")); - OUnit.assert_bool __LOC__ (not (Ext_string.no_slash "/ahgoh")); - OUnit.assert_bool __LOC__ (not (Ext_string.no_slash "/ahgoh/")) ); ( __LOC__ >:: fun _ -> OUnit.assert_bool __LOC__ (Ext_string.compare "" "" = 0); OUnit.assert_bool __LOC__ (Ext_string.compare "0" "0" = 0); @@ -206,83 +158,6 @@ let suites = ("incosistent " ^ x ^ " " ^ y ^ " " ^ string_of_int a ^ " " ^ string_of_int b) done ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ - (Ext_string.equal (Ext_string.concat3 "a0" "a1" "a2") "a0a1a2"); - OUnit.assert_bool __LOC__ - (Ext_string.equal (Ext_string.concat3 "a0" "a11" "") "a0a11"); - - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat4 "a0" "a1" "a2" "a3") - "a0a1a2a3"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat4 "a0" "a11" "" "a33") - "a0a11a33") ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ - (Ext_string.equal (Ext_string.inter2 "a0" "a1") "a0 a1"); - OUnit.assert_bool __LOC__ - (Ext_string.equal (Ext_string.inter3 "a0" "a1" "a2") "a0 a1 a2"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.inter4 "a0" "a1" "a2" "a3") - "a0 a1 a2 a3") ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx "" < 0); - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx "xxx" < 0); - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx "xxx/" = 3); - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx "xxx/g/" = 3); - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx "/xxx/g/" = 0) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx_from "xxx" 0 < 0); - OUnit.assert_bool __LOC__ (Ext_string.no_slash_idx_from "xxx/" 1 = 3); - OUnit.assert_bool __LOC__ - (Ext_string.no_slash_idx_from "xxx/g/" 4 = 5); - OUnit.assert_bool __LOC__ - (Ext_string.no_slash_idx_from "xxx/g/" 3 = 3); - OUnit.assert_bool __LOC__ - (Ext_string.no_slash_idx_from "/xxx/g/" 0 = 0) ); - ( __LOC__ >:: fun _ -> - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space [||]) - Ext_string.empty); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space [| "a0" |]) - "a0"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "a0"; "a1" |]) - "a0 a1"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "a0"; "a1"; "a2" |]) - "a0 a1 a2"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "a0"; "a1"; "a2"; "a3" |]) - "a0 a1 a2 a3"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "a0"; "a1"; "a2"; "a3"; ""; "a4" |]) - "a0 a1 a2 a3 a4"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "0"; "a1"; "2"; "a3"; ""; "a4" |]) - "0 a1 2 a3 a4"); - OUnit.assert_bool __LOC__ - (Ext_string.equal - (Ext_string.concat_array Ext_string.single_space - [| "0"; "a1"; "2"; "3"; "d"; ""; "e" |]) - "0 a1 2 3 d e") ); ( __LOC__ >:: fun _ -> let ( =~ ) = OUnit.assert_equal ~printer:(fun x -> x) in let f = Ext_string.capitalize_ascii in diff --git a/jscomp/ounit_tests/ounit_utf8_test.ml b/jscomp/ounit_tests/ounit_utf8_test.ml deleted file mode 100644 index 6d8f5dfab5..0000000000 --- a/jscomp/ounit_tests/ounit_utf8_test.ml +++ /dev/null @@ -1,32 +0,0 @@ -(* https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt -*) - -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) -let ( =~ ) = OUnit.assert_equal - -let suites = - __FILE__ - >::: [ - ( __LOC__ >:: fun _ -> - Ext_utf8.decode_utf8_string "hello 你好,中华民族 hei" - =~ [ - 104; - 101; - 108; - 108; - 111; - 32; - 20320; - 22909; - 65292; - 20013; - 21326; - 27665; - 26063; - 32; - 104; - 101; - 105; - ] ); - (__LOC__ >:: fun _ -> Ext_utf8.decode_utf8_string "" =~ []); - ] diff --git a/jscomp/ounit_tests/ounit_util_tests.ml b/jscomp/ounit_tests/ounit_util_tests.ml deleted file mode 100644 index 79fc658fa0..0000000000 --- a/jscomp/ounit_tests/ounit_util_tests.ml +++ /dev/null @@ -1,49 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) -let ( =~ ) = OUnit.assert_equal ~printer:Ounit_test_util.dump - -let add_int_3 buf (x : int) = - Buffer.add_int8 buf (x land 0xff); - Buffer.add_int16_le buf (x lsr 8) - -let suites = - __FILE__ - >::: [ - ( __LOC__ >:: fun _ -> - Ext_pervasives.nat_of_string_exn "003" =~ 3; - (try - Ext_pervasives.nat_of_string_exn "0a" |> ignore; - 2 - with _ -> -1) - =~ -1 ); - ( __LOC__ >:: fun _ -> - let cursor = ref 0 in - let v = Ext_pervasives.parse_nat_of_string "123a" cursor in - (v, !cursor) =~ (123, 3); - cursor := 0; - let v = Ext_pervasives.parse_nat_of_string "a" cursor in - (v, !cursor) =~ (0, 0) ); - ( __LOC__ >:: fun _ -> - for i = 0 to 0xff do - let buf = Buffer.create 0 in - Buffer.add_int8 buf i; - let s = Buffer.contents buf in - s =~ String.make 1 (Char.chr i); - Ext_string.get_int_1 s 0 =~ i - done ); - ( __LOC__ >:: fun _ -> - for i = 0x100 to 0xff_ff do - let buf = Buffer.create 0 in - Buffer.add_int16_le buf i; - let s = Buffer.contents buf in - Ext_string.get_int_2 s 0 =~ i - done; - let buf = Buffer.create 0 in - add_int_3 buf 0x1_ff_ff; - Buffer.length buf =~ 3; - Ext_string.get_int_3 (Buffer.contents buf) 0 =~ 0x1_ff_ff; - let buf = Buffer.create 0 in - Buffer.add_int32_le buf 0x1_ff_ff_ffl; - Ext_string.get_int_4 (Buffer.contents buf) 0 =~ 0x1_ff_ff_ff ); - ( __LOC__ >:: fun _ -> - String.length (Digest.to_hex (Digest.string "")) =~ 32 ); - ] From dee304cd9b43b5c90f444a52da83ef28433f41af Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 23 Apr 2023 21:40:17 -0700 Subject: [PATCH 2/2] fix loc --- jscomp/ounit_tests/ounit_list_test.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/ounit_tests/ounit_list_test.ml b/jscomp/ounit_tests/ounit_list_test.ml index bd16d14417..3c579529d3 100644 --- a/jscomp/ounit_tests/ounit_list_test.ml +++ b/jscomp/ounit_tests/ounit_list_test.ml @@ -65,7 +65,7 @@ let suites = "z" ); ( __LOC__ >:: fun _ -> OUnit.assert_raises - (Assert_failure ("jscomp/ext/ext_list.ml", 666, 35)) + (Assert_failure ("jscomp/ext/ext_list.ml", 591, 35)) (fun _ -> ignore @@ Ext_list.assoc_by_int [ (2, "x"); (3, "y"); (1, "z") ] 11 None)