diff --git a/CHANGES.md b/CHANGES.md index c2313e1..12b6603 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 0.1.0 - 2021-12-29 +## [0.1.1] - 2021-12-31 +### Added +- Support for `int32`, `int64`, and `nativeint`. +- `*.{make_pp_int,make_to_string}` with optional arguments. + +## [0.1.0] - 2021-12-29 Initial release. diff --git a/README.md b/README.md index f0d179c..f625d0e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,15 @@ The library provides four main functions. - `Int.pp_int` is a simple `Format` module style pretty printer. - `Int.pp_binary_int ~flags ~min_width` is a customizable `Format` module style pretty printer. +There are also versions available for `int32`, `int64`, and `nativeint` in the +modules +- `Int32`, +- `Int64`, and +- `Nativeint`. + +A generic functor to generate binary-int printers is provided in the `MakePP` +module. + ## Basic use ```ocaml diff --git a/dune-project b/dune-project index 258c06c..ee68a97 100644 --- a/dune-project +++ b/dune-project @@ -7,7 +7,7 @@ (maintainers "Ifaz Kabir") (source (github ifazk/pp-binary-ints)) (documentation https://ifazk.github.io/pp-binary-ints/) -(version 0.1.0) +(version 0.1.1) (package (name pp-binary-ints) diff --git a/lib/Flags.ml b/lib/Flags.ml new file mode 100644 index 0000000..57254f9 --- /dev/null +++ b/lib/Flags.ml @@ -0,0 +1,22 @@ +type padding = + | Left + | Right (* default *) + | Zeros + +type zero_printing = + | OCaml (* depends on padding setting: bunch of zeros (no separators, no prefixs), or space padding on the left or right *) + | InheritNonZero + +type flags = + { padding: padding + ; separators: bool + ; prefix_non_zero: bool + ; zero_printing: zero_printing + } + +let default = + { padding = Right + ; separators = false + ; prefix_non_zero = false + ; zero_printing = OCaml + } diff --git a/lib/Flags.mli b/lib/Flags.mli new file mode 100644 index 0000000..5a7ca96 --- /dev/null +++ b/lib/Flags.mli @@ -0,0 +1,21 @@ +(** The Flags module contains types to modify how binary integers are + printed. *) + +type padding = Left | Right | Zeros +(** [padding] controls whether spaces are are added on the left or right or if + zero prefixes are added. *) + +type zero_printing = OCaml | InheritNonZero +(** [zero_printing] controls whether zeros printed similar to how [Printf] + prints zeros or if zeros are printed similar to non-zero integers. *) + +type flags = { + padding : padding; + separators : bool; + prefix_non_zero : bool; + zero_printing : zero_printing; +} +(** [flags] are passed to pretty printing functions to customize the output. *) + +val default : flags +(** A default set of flags. *) diff --git a/lib/index.mld b/lib/index.mld index cf38698..8379a82 100644 --- a/lib/index.mld +++ b/lib/index.mld @@ -2,8 +2,7 @@ A library for pretty printing boolean integers. {1 Library pp-binary-ints} -The entry point of this library is the module: -{!module-Pp_binary_ints.module-Int}. +The entry point of this library is the module: {!module-Pp_binary_ints}. {1 Examples} @@ -16,8 +15,15 @@ The library provides four main functions. {- {!module-Pp_binary_ints.module-Int.val-pp_binary_int} is a customizable {!module-Format} module style pretty printer which takes in named arguments [~flags] and [~min_width].} } -The options to customize the outputs can be found in {!module-Pp_binary_ints.Int.Flags}. +The options to customize the outputs can be found in {!module-Pp_binary_ints.Flags}. +We also offer versions of these functions for `int32`, `int64`, `nativeint`, in +the following modules. +{ul + {- {!module-Pp_binary_ints.module-Int32}} + {- {!module-Pp_binary_ints.module-Int64}} + {- {!module-Pp_binary_ints.module-Nativeint}} +} {2 Basic use} diff --git a/lib/int.ml b/lib/int.ml index d1057b9..25ec893 100644 --- a/lib/int.ml +++ b/lib/int.ml @@ -1,160 +1,10 @@ -module Int = Stdlib.Int +module Int: MakePP.S with type t = int = Stdlib.Int -module Flags = struct - type padding = - | Left - | Right (* default *) - | Zeros - - type zero_printing = - | OCaml (* depends on padding setting: bunch of zeros (no separators, no prefixs), or space padding on the left or right *) - | InheritNonZero - - type flags = - { padding: padding - ; separators: bool - ; prefix_non_zero: bool - ; zero_printing: zero_printing - } - - let default = - { padding = Right - ; separators = false - ; prefix_non_zero = false - ; zero_printing = OCaml - } +module Dec = struct + let prefix = "0b" + let suffix = "" end -(* Underscore printing is tricky. - Underscores and prefixes both count towards min width. - Min width 5, no prefix, zero padding. - Ob1111 should be printed as 01111, not _1111 - Min width 6, prefix. - Ob1111 should be printed as 0b1111. - Min width 5, with prefix. - 0b111 should be printed as 0b111. - *) - -(* Utilities *) -let nat_pred n = - if (n > 0) then - n - 1 - else - 0 - -let drop_next_bit rev_bits = - rev_bits lsr 1 - -let get_next_bit_char rev_bits = - if Int.equal 0 (Int.logand 1 rev_bits) then - '0' - else - '1' - -(* The next few functions assume zero padding. - For space padding, 1 will be passed as the min_width - If prefix is set to false, then 0 will be passed as the prefix_size. -*) -let not_at_end ~(min_width:int) ~prefix_size rev_bits = - ((rev_bits <> 0) || (min_width > prefix_size)) - -let last_padding ~min_width ~prefix_size rev_bits = - let open Int in - equal rev_bits 0 && - equal min_width (prefix_size + 1) - -let print_underscore ~min_width ~count ~separators ~prefix_size rev_bits = - let open Int in - separators && - (equal 0 ((count + 1) mod 5)) && - (not_at_end ~min_width ~prefix_size rev_bits) && - (not (last_padding ~min_width ~prefix_size rev_bits)) - -let rec push_chars ~buf ~separators ~prefix_size ~min_width ~count rev_bits : unit = - if print_underscore ~min_width ~count ~separators ~prefix_size rev_bits then - ( Buffer.add_char buf '_' - ; push_chars ~buf ~separators ~prefix_size ~min_width:(nat_pred min_width) ~count:(count + 1) rev_bits - ) - else if (not_at_end ~min_width ~prefix_size rev_bits) then - ( Buffer.add_char buf (get_next_bit_char rev_bits) - ; let rev_bits = drop_next_bit rev_bits in - let min_width = nat_pred min_width in - let count = count + 1 in - push_chars ~buf ~separators ~prefix_size - ~min_width - ~count - rev_bits - ) - else - () - -let rev_buffer ~separators ~prefix ~min_width n : Buffer.t = - let buf = Buffer.create 16 in (* TODO: consider min_width for initial size *) - let prefix_size = (if prefix then 2 else 0) in - ( push_chars ~buf ~separators ~prefix_size ~min_width ~count:0 n - ; if prefix then - begin - Buffer.add_char buf 'b'; - Buffer.add_char buf '0'; - end - ; buf - ) - -(* end of assuming zero padding *) - -let pp_spaces fmt n = - for _ = 1 to n do - Format.pp_print_char fmt ' '; - done - -let pp_rev_buffer fmt buf = - let len = Buffer.length buf in - for i = 1 to len do - Format.pp_print_char fmt (Buffer.nth buf (len - i)) - done - -let pp_binary_int ~flags ~min_width fmt n = - let open Flags in - let min_width = max 1 min_width in - let {padding; prefix_non_zero; separators; zero_printing} = flags in - let buf = - match padding with - | Left | Right -> - let prefix = prefix_non_zero && ((not (Int.equal 0 n)) || (zero_printing = InheritNonZero)) in - let min_width = if prefix then 3 else 1 in - rev_buffer - ~separators - ~prefix - ~min_width - n - | Zeros -> - if (zero_printing = OCaml) && Int.equal n 0 then - rev_buffer ~separators:false ~prefix:false ~min_width 0 - else - let prefix = prefix_non_zero in - let min_width = max min_width (if prefix then 3 else 1) in - rev_buffer ~separators ~prefix ~min_width n - in - let len = Buffer.length buf in - match padding with - | Left -> - begin - pp_spaces fmt (min_width - len); - pp_rev_buffer fmt buf; - end - | Right -> - begin - pp_rev_buffer fmt buf; - pp_spaces fmt (min_width - len); - end - | Zeros -> - pp_rev_buffer fmt buf - -let pp_int fmt n = - pp_binary_int ~flags:(Flags.default) ~min_width:1 fmt n - -let to_string n : string = - Format.asprintf "%a" pp_int n +module Flags = Flags -let to_string_with ~flags ~min_width : int -> string = - Format.asprintf "%a" (pp_binary_int ~flags ~min_width) +include (MakePP.Make (Int) (Dec)) diff --git a/lib/int.mli b/lib/int.mli index a16d720..9e130d7 100644 --- a/lib/int.mli +++ b/lib/int.mli @@ -1,3 +1,5 @@ +type t = int + module Flags : sig (** The Flags module contains types to modify how binary integers are printed. *) @@ -33,6 +35,13 @@ val pp_binary_int : val pp_int : Format.formatter -> int -> unit (** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the formatter [fmt]. *) +val make_pp_int : + ?flags:Flags.flags -> ?min_width:int -> unit -> Format.formatter -> int -> unit +(** [make_pp_int ?flags ?min_width ()] is just [pp_binary_int ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to pp_binary_int. This version + is nicer to with with the [Format] or [Fmt] modules. *) + val to_string_with : flags:Flags.flags -> min_width:int -> int -> string (** [to_string_width ~flags ~min_width n] converts the integer [n] to a binary integer [n]. customizing the output with [~flags]. [~min_width] pads the @@ -41,3 +50,9 @@ val to_string_with : flags:Flags.flags -> min_width:int -> int -> string val to_string : int -> string (** [to_string n] converts the integer [n] to a binary integer [n]. *) + +val make_to_string : + ?flags:Flags.flags -> ?min_width:int -> unit -> int -> string +(** [make_to_string ?flags ?min_width ()] is just [to_string_with ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to to_string_with. *) diff --git a/lib/int32.ml b/lib/int32.ml new file mode 100644 index 0000000..fa762fd --- /dev/null +++ b/lib/int32.ml @@ -0,0 +1,8 @@ +module I: Internal.S with type t = int32 = Stdlib.Int32 + +module Dec = struct + let prefix = "0b" + let suffix = "l" +end + +include (MakePP.Make (I) (Dec)) diff --git a/lib/int32.mli b/lib/int32.mli new file mode 100644 index 0000000..e145714 --- /dev/null +++ b/lib/int32.mli @@ -0,0 +1,33 @@ +type t = int32 + +val pp_binary_int : + flags:Flags.flags -> min_width:int -> Format.formatter -> int32 -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the + formatter [fmt], customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val pp_int : Format.formatter -> int32 -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the formatter [fmt]. *) + +val make_pp_int : + ?flags:Flags.flags -> ?min_width:int -> unit -> Format.formatter -> int32 -> unit +(** [make_pp_int ?flags ?min_width ()] is just [pp_binary_int ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to pp_binary_int. This version + is nicer to with with the [Format] or [Fmt] modules. *) + +val to_string_with : flags:Flags.flags -> min_width:int -> int32 -> string +(** [to_string_width ~flags ~min_width n] converts the integer [n] to a binary + integer [n]. customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val to_string : int32 -> string +(** [to_string n] converts the integer [n] to a binary integer [n]. *) + +val make_to_string : + ?flags:Flags.flags -> ?min_width:int -> unit -> int32 -> string +(** [make_to_string ?flags ?min_width ()] is just [to_string_with ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to to_string_with. *) diff --git a/lib/int64.ml b/lib/int64.ml new file mode 100644 index 0000000..73ab697 --- /dev/null +++ b/lib/int64.ml @@ -0,0 +1,8 @@ +module I: Internal.S with type t = int64 = Stdlib.Int64 + +module Dec = struct + let prefix = "0b" + let suffix = "L" +end + +include (MakePP.Make (I) (Dec)) diff --git a/lib/int64.mli b/lib/int64.mli new file mode 100644 index 0000000..33a2459 --- /dev/null +++ b/lib/int64.mli @@ -0,0 +1,33 @@ +type t = int64 + +val pp_binary_int : + flags:Flags.flags -> min_width:int -> Format.formatter -> int64 -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the + formatter [fmt], customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val pp_int : Format.formatter -> int64 -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the formatter [fmt]. *) + +val make_pp_int : + ?flags:Flags.flags -> ?min_width:int -> unit -> Format.formatter -> int64 -> unit +(** [make_pp_int ?flags ?min_width ()] is just [pp_binary_int ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to pp_binary_int. This version + is nicer to with with the [Format] or [Fmt] modules. *) + +val to_string_with : flags:Flags.flags -> min_width:int -> int64 -> string +(** [to_string_width ~flags ~min_width n] converts the integer [n] to a binary + integer [n]. customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val to_string : int64 -> string +(** [to_string n] converts the integer [n] to a binary integer [n]. *) + +val make_to_string : + ?flags:Flags.flags -> ?min_width:int -> unit -> int64 -> string +(** [make_to_string ?flags ?min_width ()] is just [to_string_with ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to to_string_with. *) diff --git a/lib/internal.ml b/lib/internal.ml new file mode 100644 index 0000000..1cf190d --- /dev/null +++ b/lib/internal.ml @@ -0,0 +1,193 @@ +(** This module is interal to pp-binary-ints and is subject to change without + notice. *) + +module IntUtils = struct + let nat_pred n = + if (n > 0) then + n - 1 + else + 0 + + let nat_minus n m = + let sub = n - m in + if (sub > 0) then + sub + else + 0 +end + +module PPUtils = struct + + let pp_spaces fmt n = + for _ = 1 to n do + Format.pp_print_char fmt ' '; + done + + let pp_rev_buffer fmt buf = + let len = Buffer.length buf in + for i = 1 to len do + Format.pp_print_char fmt (Buffer.nth buf (len - i)) + done + +end + +module type S = sig + type t + + val zero : t + val one : t + val logand : t -> t -> t + val equal : t -> t -> bool + val shift_right_logical : t -> int -> t +end + +module type D = sig + val prefix : string + val suffix : string +end + +module MakeDecorators (Dec : D) = struct + include Dec + let prefix_size = String.length prefix + let suffix_size = String.length suffix + + let push_rev_prefix buf = + for i = 1 to prefix_size do + Buffer.add_char buf (String.get prefix (prefix_size - i)) + done + + let push_rev_suffix buf = + for i = 1 to suffix_size do + Buffer.add_char buf (String.get suffix (suffix_size - i)) + done +end + +module Make (I : S) (Dec : D) = struct +(* Underscore printing is tricky. + Underscores and prefixes both count towards min width. + Min width 5, no prefix, zero padding. + Ob1111 should be printed as 01111, not _1111 + Min width 6, prefix. + Ob1111 should be printed as 0b1111. + Min width 5, with prefix. + 0b111 should be printed as 0b111. + *) + + module Decorators = MakeDecorators (Dec) + + (* Utilities *) + let drop_next_bit rev_bits = + I.shift_right_logical rev_bits 1 + + let get_next_bit_char rev_bits = + if I.equal I.zero (I.logand I.one rev_bits) then + '0' + else + '1' + + (* The next few functions assume zero padding. + For space padding, 1 will be passed as the min_width + If prefix is set to false, then 0 will be passed as the prefix_size. + *) + let not_at_end ~(min_width:int) ~prefix_size rev_bits = + ((rev_bits <> I.zero) || (min_width > prefix_size)) + + let last_padding ~min_width ~prefix_size rev_bits = + let open I in + equal rev_bits zero && + (prefix_size + 1) = min_width + + let print_underscore ~min_width ~count ~separators ~prefix_size rev_bits = + separators && + (0 = ((count + 1) mod 5)) && + (not_at_end ~min_width ~prefix_size rev_bits) && + (not (last_padding ~min_width ~prefix_size rev_bits)) + + let rec push_chars ~buf ~separators ~prefix_size ~min_width ~count rev_bits : unit = + if print_underscore ~min_width ~count ~separators ~prefix_size rev_bits then + ( Buffer.add_char buf '_' + ; push_chars ~buf ~separators ~prefix_size ~min_width:(IntUtils.nat_pred min_width) ~count:(count + 1) rev_bits + ) + else if (not_at_end ~min_width ~prefix_size rev_bits) then + ( Buffer.add_char buf (get_next_bit_char rev_bits) + ; let rev_bits = drop_next_bit rev_bits in + let min_width = IntUtils.nat_pred min_width in + let count = count + 1 in + push_chars ~buf ~separators ~prefix_size + ~min_width + ~count + rev_bits + ) + else + () + + let push_bit_chars ~buf ~separators ~prefix_size ~min_width rev_bits : unit = + let min_width = max (1 + prefix_size) min_width in + push_chars ~buf ~separators ~prefix_size ~min_width ~count:0 rev_bits + + let rev_buffer ~separators ~prefix ~min_width n : Buffer.t = + let buf = Buffer.create 16 in (* TODO: consider min_width for initial size *) + let prefix_size = (if prefix then Decorators.prefix_size else 0) in + ( Decorators.push_rev_suffix buf + ; push_bit_chars ~buf ~separators ~prefix_size ~min_width:(IntUtils.nat_minus min_width Decorators.suffix_size) n + ; if prefix then + Decorators.push_rev_prefix buf + ; buf + ) + + (* end of assuming zero padding *) + + + let pp_binary_int ~flags ~min_width fmt n = + let open Flags in + let min_width = max 1 min_width in + let {padding; prefix_non_zero; separators; zero_printing} = flags in + let buf = + match padding with + | Left | Right -> + let prefix = prefix_non_zero && ((not (I.equal I.zero n)) || (zero_printing = InheritNonZero)) in + let min_width = 1 in + rev_buffer + ~separators + ~prefix + ~min_width + n + | Zeros -> + if (zero_printing = OCaml) && I.equal n I.zero then + rev_buffer ~separators ~prefix:false ~min_width I.zero + else + let prefix = prefix_non_zero in + let min_width = max min_width (if prefix then 3 else 1) in + rev_buffer ~separators ~prefix ~min_width n + in + let len = Buffer.length buf in + match padding with + | Left -> + begin + PPUtils.pp_spaces fmt (min_width - len); + PPUtils.pp_rev_buffer fmt buf; + end + | Right -> + begin + PPUtils.pp_rev_buffer fmt buf; + PPUtils.pp_spaces fmt (min_width - len); + end + | Zeros -> + PPUtils.pp_rev_buffer fmt buf + + + let make_pp_int ?(flags=Flags.default) ?(min_width=1) () = + pp_binary_int ~flags ~min_width + + let pp_int fmt n = + pp_binary_int ~flags:(Flags.default) ~min_width:1 fmt n + + let to_string n : string = + Format.asprintf "%a" pp_int n + + let to_string_with ~flags ~min_width : I.t -> string = + Format.asprintf "%a" (pp_binary_int ~flags ~min_width) + + let make_to_string ?(flags=Flags.default) ?(min_width=1) () = + to_string_with ~flags ~min_width +end diff --git a/lib/makePP.ml b/lib/makePP.ml new file mode 100644 index 0000000..64a21a8 --- /dev/null +++ b/lib/makePP.ml @@ -0,0 +1,21 @@ +(** This module provides functions create your own binary-int-printers. *) + +module type S = sig + type t + + val zero : t + val one : t + val logand : t -> t -> t + val equal : t -> t -> bool + val shift_right_logical : t -> int -> t +end + +module type D = sig + val prefix : string + val suffix : string +end + +module Make (I : S) (Dec : D) = struct + type t = I.t + include (Internal.Make (I) (Dec)) +end diff --git a/lib/makePP.mli b/lib/makePP.mli new file mode 100644 index 0000000..3cf1b6b --- /dev/null +++ b/lib/makePP.mli @@ -0,0 +1,52 @@ +(** This module provides functions create your own binary-int-printers. *) + +module type S = sig + (** Operations on integers usid in pretty printing. *) + + type t + val zero : t + val one : t + val logand : t -> t -> t + val equal : t -> t -> bool + val shift_right_logical : t -> int -> t +end + +module type D = sig + (** Module type for prefixes and suffixes. *) + + val prefix : string + val suffix : string +end + +module Make (I : S) (Dec : D) : sig + type t = I.t + + val pp_binary_int : flags:Flags.flags -> min_width:int -> Format.formatter -> I.t -> unit + (** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the + formatter [fmt], customizing the output with [~flags]. [~min_width] pads + the output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + + val pp_int : Format.formatter -> I.t -> unit + (** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the formatter [fmt]. *) + + val make_pp_int : ?flags:Flags.flags -> ?min_width:int -> unit -> Format.formatter -> I.t -> unit + (** [make_pp_int ?flags ?min_width ()] is just [pp_binary_int ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to pp_binary_int. This + version is nicer to with with the [Format] or [Fmt] modules. *) + + val to_string_with : flags:Flags.flags -> min_width:int -> I.t -> string + (** [to_string_width ~flags ~min_width n] converts the integer [n] to a binary + integer [n]. customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + + val to_string : I.t -> string + (** [to_string n] converts the integer [n] to a binary integer [n]. *) + + val make_to_string : ?flags:Flags.flags -> ?min_width:int -> unit -> I.t -> string + (** [make_to_string ?flags ?min_width ()] is just [to_string_with ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to to_string_with. *) +end diff --git a/lib/nativeint.ml b/lib/nativeint.ml new file mode 100644 index 0000000..975c3dc --- /dev/null +++ b/lib/nativeint.ml @@ -0,0 +1,8 @@ +module I: Internal.S with type t = nativeint = Stdlib.Nativeint + +module Dec = struct + let prefix = "0b" + let suffix = "n" +end + +include (MakePP.Make (I) (Dec)) diff --git a/lib/nativeint.mli b/lib/nativeint.mli new file mode 100644 index 0000000..105f36a --- /dev/null +++ b/lib/nativeint.mli @@ -0,0 +1,33 @@ +type t = nativeint + +val pp_binary_int : + flags:Flags.flags -> min_width:int -> Format.formatter -> nativeint -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the + formatter [fmt], customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val pp_int : Format.formatter -> nativeint -> unit +(** [pp_binary_int ~flags ~min_width fmt n] prints the integer [n] on the formatter [fmt]. *) + +val make_pp_int : + ?flags:Flags.flags -> ?min_width:int -> unit -> Format.formatter -> nativeint -> unit +(** [make_pp_int ?flags ?min_width ()] is just [pp_binary_int ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to pp_binary_int. This version + is nicer to with with the [Format] or [Fmt] modules. *) + +val to_string_with : flags:Flags.flags -> min_width:int -> nativeint -> string +(** [to_string_width ~flags ~min_width n] converts the integer [n] to a binary + integer [n]. customizing the output with [~flags]. [~min_width] pads the + output with enough spaces or zeros so that the output is at least + [~min_width] characters, depends on [flags.padding]. *) + +val to_string : nativeint -> string +(** [to_string n] converts the integer [n] to a binary integer [n]. *) + +val make_to_string : + ?flags:Flags.flags -> ?min_width:int -> unit -> nativeint -> string +(** [make_to_string ?flags ?min_width ()] is just [to_string_with ~flags + ~min_width], but [flags] and [min_width] are optional. If omitted default + values of [Flags.default] and [1] are passed to to_string_with. *) diff --git a/pp-binary-ints.opam b/pp-binary-ints.opam index bf1e54f..562ef83 100644 --- a/pp-binary-ints.opam +++ b/pp-binary-ints.opam @@ -1,6 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -version: "0.1.0" +version: "0.1.1" synopsis: "Pretty Printing Binary Integers" description: """ Pretty Printing Binary Integers diff --git a/test/large.ml b/test/large.ml index 8df3b29..794f1d5 100644 --- a/test/large.ml +++ b/test/large.ml @@ -358,3 +358,173 @@ let%test "left inherit 16" = let%test "right inherit 16" = ["110111 ";"0b110111 ";"11_0111 ";"0b11_0111 "] = test_width right_inherit_configs 16 0b110111 + +(** * -1 printing *) + +let%test "zero inherit -1 1" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 1 (-1) + +let%test "left inherit -1 1" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 1 (-1) + +let%test "right inherit -1 1" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 1 (-1) + +let%test "zero inherit -1 64" [@tags "64-bits-only"] = + ["0111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 64 (-1) + +let%test "left inherit -1 64" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 64 (-1) + +let%test "right inherit -1 64" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 64 (-1) + +let%test "zero inherit -1 65" [@tags "64-bits-only"] = + ["00111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 65 (-1) + +let%test "left inherit -1 65" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 65 (-1) + +let%test "right inherit -1 65" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 65 (-1) + +let%test "zero inherit -1 78" [@tags "64-bits-only"] = + ["000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0b0000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 78 (-1) + +let%test "left inherit -1 78" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;" 0b111111111111111111111111111111111111111111111111111111111111111" + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 78 (-1) + +let%test "right inherit -1 78" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111 " + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 78 (-1) + +let%test "zero inherit -1 79" [@tags "64-bits-only"] = + ["0000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0b00000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 79 (-1) + +let%test "left inherit -1 79" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;" 0b111111111111111111111111111111111111111111111111111111111111111" + ;" 111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 79 (-1) + +let%test "right inherit -1 79" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111 " + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111 " + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 79 (-1) + +let%test "zero inherit -1 80" [@tags "64-bits-only"] = + ["00000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0b000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"00111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 80 (-1) + +let%test "left inherit -1 80" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;" 0b111111111111111111111111111111111111111111111111111111111111111" + ;" 111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 80 (-1) + +let%test "right inherit -1 80" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111 " + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111 " + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width right_inherit_configs 80 (-1) + +let%test "zero inherit -1 81" [@tags "64-bits-only"] = + ["000000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0b0000000000000000111111111111111111111111111111111111111111111111111111111111111" + ;"0_0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;"0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width zero_inherit_configs 81 (-1) + +let%test "left inherit -1 81" [@tags "64-bits-only"] = + [" 111111111111111111111111111111111111111111111111111111111111111" + ;" 0b111111111111111111111111111111111111111111111111111111111111111" + ;" 111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ;" 0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" + ] = + test_width left_inherit_configs 81 (-1) + +let%test "right inherit -1 81" [@tags "64-bits-only"] = + ["111111111111111111111111111111111111111111111111111111111111111 " + ;"0b111111111111111111111111111111111111111111111111111111111111111 " + ;"111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111 " + ;"0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111 " + ] = + test_width right_inherit_configs 81 (-1) diff --git a/test/large_int32.ml b/test/large_int32.ml new file mode 100644 index 0000000..feb2e1f --- /dev/null +++ b/test/large_int32.ml @@ -0,0 +1,538 @@ +open Pp_binary_ints.Int32 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Five printing *) + +let%test "one default" = + "101l" = + to_string 0b101l + +let%test "one default manual" = + "101l" = + to_string_with ~flags:default ~min_width:1 0b101l + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width zero_inherit_configs 1 0b101l + +let%test "zero inherit 2" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width zero_inherit_configs 2 0b101l + +let%test "zero inherit 3" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width zero_inherit_configs 3 0b101l + +let%test "zero inherit 4" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width zero_inherit_configs 4 0b101l + +let%test "zero inherit 5" = + ["0101l" + ;"0b101l" + ;"0101l" + ;"0b101l" + ] = + test_width zero_inherit_configs 5 0b101l + +let%test "zero inherit 6" = + ["00101l" + ;"0b101l" + ;"00101l" + ;"0b101l" + ] = + test_width zero_inherit_configs 6 0b101l + +let%test "zero inherit 7" = + ["000101l" + ;"0b0101l" + ;"0_0101l" + ;"0b0101l"] = + test_width zero_inherit_configs 7 0b101l + +let%test "zero inherit 8" = + ["0000101l" + ;"0b00101l" + ;"00_0101l" + ;"0b00101l"] = + test_width zero_inherit_configs 8 0b101l + +let%test "zero inherit 9" = + ["00000101l" + ;"0b000101l" + ;"000_0101l" + ;"0b0_0101l"] = + test_width zero_inherit_configs 9 0b101l + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width left_inherit_configs 1 0b101l + +let%test "left inherit 2" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width left_inherit_configs 2 0b101l + +let%test "left inherit 3" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width left_inherit_configs 3 0b101l + +let%test "left inherit 4" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width left_inherit_configs 4 0b101l + +let%test "left inherit 5" = + [" 101l";"0b101l";" 101l";"0b101l"] = + test_width left_inherit_configs 5 0b101l + +let%test "left inherit 6" = + [" 101l";"0b101l";" 101l";"0b101l"] = + test_width left_inherit_configs 6 0b101l + +let%test "left inherit 7" = + [" 101l";" 0b101l";" 101l";" 0b101l"] = + test_width left_inherit_configs 7 0b101l + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width right_inherit_configs 1 0b101l + +let%test "right inherit 2" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width right_inherit_configs 2 0b101l + +let%test "right inherit 3" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width right_inherit_configs 3 0b101l + +let%test "right inherit 4" = + ["101l";"0b101l";"101l";"0b101l"] = + test_width right_inherit_configs 4 0b101l + +let%test "right inherit 5" = + ["101l ";"0b101l";"101l ";"0b101l"] = + test_width right_inherit_configs 5 0b101l + +let%test "right inherit 6" = + ["101l ";"0b101l";"101l ";"0b101l"] = + test_width right_inherit_configs 6 0b101l + +let%test "right inherit 7" = + ["101l ";"0b101l ";"101l ";"0b101l "] = + test_width right_inherit_configs 7 0b101l + +(** * Eight printing *) + +let%test "one default" = + "1000l" = + to_string 0b1000l + +let%test "one default manual" = + "1000l" = + to_string_with ~flags:default ~min_width:1 0b1000l + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width zero_inherit_configs 1 0b1000l + +let%test "zero inherit 2" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width zero_inherit_configs 2 0b1000l + +let%test "zero inherit 3" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width zero_inherit_configs 3 0b1000l + +let%test "zero inherit 4" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width zero_inherit_configs 4 0b1000l + +let%test "zero inherit 5" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width zero_inherit_configs 5 0b1000l + +let%test "zero inherit 6" = + ["01000l";"0b1000l";"01000l";"0b1000l"] = + test_width zero_inherit_configs 6 0b1000l + +let%test "zero inherit 7" = + ["001000l";"0b1000l";"0_1000l";"0b1000l"] = + test_width zero_inherit_configs 7 0b1000l + +let%test "zero inherit 8" = + ["0001000l";"0b01000l";"00_1000l";"0b01000l"] = + test_width zero_inherit_configs 8 0b1000l + +let%test "zero inherit 9" = + ["00001000l";"0b001000l";"000_1000l";"0b0_1000l"] = + test_width zero_inherit_configs 9 0b1000l + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width left_inherit_configs 1 0b1000l + +let%test "left inherit 2" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width left_inherit_configs 2 0b1000l + +let%test "left inherit 3" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width left_inherit_configs 3 0b1000l + +let%test "left inherit 4" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width left_inherit_configs 4 0b1000l + +let%test "left inherit 5" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width left_inherit_configs 5 0b1000l + +let%test "left inherit 6" = + [" 1000l";"0b1000l";" 1000l";"0b1000l"] = + test_width left_inherit_configs 6 0b1000l + +let%test "left inherit 7" = + [" 1000l";"0b1000l";" 1000l";"0b1000l"] = + test_width left_inherit_configs 7 0b1000l + +let%test "left inherit 8" = + [" 1000l";" 0b1000l";" 1000l";" 0b1000l"] = + test_width left_inherit_configs 8 0b1000l + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width right_inherit_configs 1 0b1000l + +let%test "right inherit 2" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width right_inherit_configs 2 0b1000l + +let%test "right inherit 3" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width right_inherit_configs 3 0b1000l + +let%test "right inherit 4" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width right_inherit_configs 4 0b1000l + +let%test "right inherit 5" = + ["1000l";"0b1000l";"1000l";"0b1000l"] = + test_width right_inherit_configs 5 0b1000l + +let%test "right inherit 6" = + ["1000l ";"0b1000l";"1000l ";"0b1000l"] = + test_width right_inherit_configs 6 0b1000l + +let%test "right inherit 7" = + ["1000l ";"0b1000l";"1000l ";"0b1000l"] = + test_width right_inherit_configs 7 0b1000l + +let%test "right inherit 8" = + ["1000l ";"0b1000l ";"1000l ";"0b1000l "] = + test_width right_inherit_configs 8 0b1000l + +(** * Seventeen printing *) + +let%test "one default" = + "10001l" = + to_string 0b10001l + +let%test "one default manual" = + "10001l" = + to_string_with ~flags:default ~min_width:1 0b10001l + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 1 0b10001l + +let%test "zero inherit 2" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 2 0b10001l + +let%test "zero inherit 3" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 3 0b10001l + +let%test "zero inherit 4" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 4 0b10001l + +let%test "zero inherit 5" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 5 0b10001l + +let%test "zero inherit 6" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 6 0b10001l + +let%test "zero inherit 7" = + ["010001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 7 0b10001l + +let%test "zero inherit 8" = + ["0010001l";"0b10001l";"01_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 8 0b10001l + +let%test "zero inherit 9" = + ["00010001l";"0b010001l";"001_0001l";"0b1_0001l"] = + test_width zero_inherit_configs 9 0b10001l + +let%test "zero inherit 10" = + ["000010001l" + ;"0b0010001l" + ;"0001_0001l" + ;"0b01_0001l"] = + test_width zero_inherit_configs 10 0b10001l + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 1 0b10001l + +let%test "left inherit 2" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 2 0b10001l + +let%test "left inherit 3" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 3 0b10001l + +let%test "left inherit 4" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 4 0b10001l + +let%test "left inherit 5" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 5 0b10001l + +let%test "left inherit 6" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 6 0b10001l + +let%test "left inherit 7" = + [" 10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 7 0b10001l + +let%test "left inherit 8" = + [" 10001l";"0b10001l";" 1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 8 0b10001l + +let%test "left inherit 9" = + [" 10001l";" 0b10001l";" 1_0001l";"0b1_0001l"] = + test_width left_inherit_configs 9 0b10001l + +let%test "left inherit 10" = + [" 10001l";" 0b10001l";" 1_0001l";" 0b1_0001l"] = + test_width left_inherit_configs 10 0b10001l + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 1 0b10001l + +let%test "right inherit 2" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 2 0b10001l + +let%test "right inherit 3" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 3 0b10001l + +let%test "right inherit 4" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 4 0b10001l + +let%test "right inherit 5" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 5 0b10001l + +let%test "right inherit 6" = + ["10001l";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 6 0b10001l + +let%test "right inherit 7" = + ["10001l ";"0b10001l";"1_0001l";"0b1_0001l"] = + test_width right_inherit_configs 7 0b10001l + +let%test "right inherit 8" = + ["10001l ";"0b10001l";"1_0001l ";"0b1_0001l"] = + test_width right_inherit_configs 8 0b10001l + +let%test "right inherit 9" = + ["10001l ";"0b10001l ";"1_0001l ";"0b1_0001l"] = + test_width right_inherit_configs 9 0b10001l + +let%test "right inherit 10" = + ["10001l ";"0b10001l ";"1_0001l ";"0b1_0001l "] = + test_width right_inherit_configs 10 0b10001l + +(** * Large printing *) + +let%test "zero inherit 17" = + ["0000000000110111l";"0b00000000110111l";"0_0000_0011_0111l";"0b0000_0011_0111l"] = + test_width zero_inherit_configs 17 0b110111l + +let%test "left inherit 17" = + [" 110111l";" 0b110111l";" 11_0111l";" 0b11_0111l"] = + test_width left_inherit_configs 17 0b110111l + +let%test "right inherit 16" = + ["110111l ";"0b110111l ";"11_0111l ";"0b11_0111l "] = + test_width right_inherit_configs 17 0b110111l + +(** * -1 printing *) + +let%test "zero inherit -1 1" = + ["11111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width zero_inherit_configs 1 (-1l) + +let%test "left inherit -1l 1" = + ["11111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width left_inherit_configs 1 (-1l) + +let%test "right inherit -1l 1" = + ["11111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width right_inherit_configs 1 (-1l) + +let%test "zero inherit -1l 34" = + ["011111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width zero_inherit_configs 34 (-1l) + +let%test "left inherit -1l 34" = + [" 11111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width left_inherit_configs 34 (-1l) + +let%test "right inherit -1l 34" = + ["11111111111111111111111111111111l " + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width right_inherit_configs 34 (-1l) + +let%test "zero inherit -1l 35" = + ["0011111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width zero_inherit_configs 35 (-1l) + +let%test "left inherit -1l 35" = + [" 11111111111111111111111111111111l" + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width left_inherit_configs 35 (-1l) + +let%test "right inherit -1l 35" = + ["11111111111111111111111111111111l " + ;"0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width right_inherit_configs 35 (-1l) + +let%test "zero inherit -1l 36" = + ["00011111111111111111111111111111111l" + ;"0b011111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width zero_inherit_configs 36 (-1l) + +let%test "left inherit -1l 36" = + [" 11111111111111111111111111111111l" + ;" 0b11111111111111111111111111111111l" + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width left_inherit_configs 36 (-1l) + +let%test "right inherit -1l 36" = + ["11111111111111111111111111111111l " + ;"0b11111111111111111111111111111111l " + ;"1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width right_inherit_configs 36 (-1l) + +let%test "zero inherit -1l 78" = + ["00000000000000000000000000000000000000000000011111111111111111111111111111111l" + ;"0b000000000000000000000000000000000000000000011111111111111111111111111111111l" + ;"00_0000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1111_1111_1111_1111l" + ;"0b00000_0000_0000_0000_0000_0000_0000_1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width zero_inherit_configs 78 (-1l) + +let%test "left inherit -1l 78" = + [" 11111111111111111111111111111111l" + ;" 0b11111111111111111111111111111111l" + ;" 1111_1111_1111_1111_1111_1111_1111_1111l" + ;" 0b1111_1111_1111_1111_1111_1111_1111_1111l" + ] = + test_width left_inherit_configs 78 (-1l) + +let%test "right inherit -1l 78" = + ["11111111111111111111111111111111l " + ;"0b11111111111111111111111111111111l " + ;"1111_1111_1111_1111_1111_1111_1111_1111l " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111l " + ] = + test_width right_inherit_configs 78 (-1l) diff --git a/test/large_int64.ml b/test/large_int64.ml new file mode 100644 index 0000000..b5525c9 --- /dev/null +++ b/test/large_int64.ml @@ -0,0 +1,682 @@ +open Pp_binary_ints.Int64 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Five printing *) + +let%test "one default" = + "101L" = + to_string 0b101L + +let%test "one default manual" = + "101L" = + to_string_with ~flags:default ~min_width:1 0b101L + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width zero_inherit_configs 1 0b101L + +let%test "zero inherit 2" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width zero_inherit_configs 2 0b101L + +let%test "zero inherit 3" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width zero_inherit_configs 3 0b101L + +let%test "zero inherit 4" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width zero_inherit_configs 4 0b101L + +let%test "zero inherit 5" = + ["0101L" + ;"0b101L" + ;"0101L" + ;"0b101L" + ] = + test_width zero_inherit_configs 5 0b101L + +let%test "zero inherit 6" = + ["00101L" + ;"0b101L" + ;"00101L" + ;"0b101L" + ] = + test_width zero_inherit_configs 6 0b101L + +let%test "zero inherit 7" = + ["000101L" + ;"0b0101L" + ;"0_0101L" + ;"0b0101L"] = + test_width zero_inherit_configs 7 0b101L + +let%test "zero inherit 8" = + ["0000101L" + ;"0b00101L" + ;"00_0101L" + ;"0b00101L"] = + test_width zero_inherit_configs 8 0b101L + +let%test "zero inherit 9" = + ["00000101L" + ;"0b000101L" + ;"000_0101L" + ;"0b0_0101L"] = + test_width zero_inherit_configs 9 0b101L + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width left_inherit_configs 1 0b101L + +let%test "left inherit 2" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width left_inherit_configs 2 0b101L + +let%test "left inherit 3" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width left_inherit_configs 3 0b101L + +let%test "left inherit 4" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width left_inherit_configs 4 0b101L + +let%test "left inherit 5" = + [" 101L";"0b101L";" 101L";"0b101L"] = + test_width left_inherit_configs 5 0b101L + +let%test "left inherit 6" = + [" 101L";"0b101L";" 101L";"0b101L"] = + test_width left_inherit_configs 6 0b101L + +let%test "left inherit 7" = + [" 101L";" 0b101L";" 101L";" 0b101L"] = + test_width left_inherit_configs 7 0b101L + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width right_inherit_configs 1 0b101L + +let%test "right inherit 2" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width right_inherit_configs 2 0b101L + +let%test "right inherit 3" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width right_inherit_configs 3 0b101L + +let%test "right inherit 4" = + ["101L";"0b101L";"101L";"0b101L"] = + test_width right_inherit_configs 4 0b101L + +let%test "right inherit 5" = + ["101L ";"0b101L";"101L ";"0b101L"] = + test_width right_inherit_configs 5 0b101L + +let%test "right inherit 6" = + ["101L ";"0b101L";"101L ";"0b101L"] = + test_width right_inherit_configs 6 0b101L + +let%test "right inherit 7" = + ["101L ";"0b101L ";"101L ";"0b101L "] = + test_width right_inherit_configs 7 0b101L + +(** * Eight printing *) + +let%test "one default" = + "1000L" = + to_string 0b1000L + +let%test "one default manual" = + "1000L" = + to_string_with ~flags:default ~min_width:1 0b1000L + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width zero_inherit_configs 1 0b1000L + +let%test "zero inherit 2" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width zero_inherit_configs 2 0b1000L + +let%test "zero inherit 3" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width zero_inherit_configs 3 0b1000L + +let%test "zero inherit 4" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width zero_inherit_configs 4 0b1000L + +let%test "zero inherit 5" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width zero_inherit_configs 5 0b1000L + +let%test "zero inherit 6" = + ["01000L";"0b1000L";"01000L";"0b1000L"] = + test_width zero_inherit_configs 6 0b1000L + +let%test "zero inherit 7" = + ["001000L";"0b1000L";"0_1000L";"0b1000L"] = + test_width zero_inherit_configs 7 0b1000L + +let%test "zero inherit 8" = + ["0001000L";"0b01000L";"00_1000L";"0b01000L"] = + test_width zero_inherit_configs 8 0b1000L + +let%test "zero inherit 9" = + ["00001000L";"0b001000L";"000_1000L";"0b0_1000L"] = + test_width zero_inherit_configs 9 0b1000L + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width left_inherit_configs 1 0b1000L + +let%test "left inherit 2" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width left_inherit_configs 2 0b1000L + +let%test "left inherit 3" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width left_inherit_configs 3 0b1000L + +let%test "left inherit 4" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width left_inherit_configs 4 0b1000L + +let%test "left inherit 5" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width left_inherit_configs 5 0b1000L + +let%test "left inherit 6" = + [" 1000L";"0b1000L";" 1000L";"0b1000L"] = + test_width left_inherit_configs 6 0b1000L + +let%test "left inherit 7" = + [" 1000L";"0b1000L";" 1000L";"0b1000L"] = + test_width left_inherit_configs 7 0b1000L + +let%test "left inherit 8" = + [" 1000L";" 0b1000L";" 1000L";" 0b1000L"] = + test_width left_inherit_configs 8 0b1000L + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width right_inherit_configs 1 0b1000L + +let%test "right inherit 2" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width right_inherit_configs 2 0b1000L + +let%test "right inherit 3" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width right_inherit_configs 3 0b1000L + +let%test "right inherit 4" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width right_inherit_configs 4 0b1000L + +let%test "right inherit 5" = + ["1000L";"0b1000L";"1000L";"0b1000L"] = + test_width right_inherit_configs 5 0b1000L + +let%test "right inherit 6" = + ["1000L ";"0b1000L";"1000L ";"0b1000L"] = + test_width right_inherit_configs 6 0b1000L + +let%test "right inherit 7" = + ["1000L ";"0b1000L";"1000L ";"0b1000L"] = + test_width right_inherit_configs 7 0b1000L + +let%test "right inherit 8" = + ["1000L ";"0b1000L ";"1000L ";"0b1000L "] = + test_width right_inherit_configs 8 0b1000L + +(** * Seventeen printing *) + +let%test "one default" = + "10001L" = + to_string 0b10001L + +let%test "one default manual" = + "10001L" = + to_string_with ~flags:default ~min_width:1 0b10001L + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 1 0b10001L + +let%test "zero inherit 2" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 2 0b10001L + +let%test "zero inherit 3" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 3 0b10001L + +let%test "zero inherit 4" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 4 0b10001L + +let%test "zero inherit 5" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 5 0b10001L + +let%test "zero inherit 6" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 6 0b10001L + +let%test "zero inherit 7" = + ["010001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 7 0b10001L + +let%test "zero inherit 8" = + ["0010001L";"0b10001L";"01_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 8 0b10001L + +let%test "zero inherit 9" = + ["00010001L";"0b010001L";"001_0001L";"0b1_0001L"] = + test_width zero_inherit_configs 9 0b10001L + +let%test "zero inherit 10" = + ["000010001L" + ;"0b0010001L" + ;"0001_0001L" + ;"0b01_0001L"] = + test_width zero_inherit_configs 10 0b10001L + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 1 0b10001L + +let%test "left inherit 2" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 2 0b10001L + +let%test "left inherit 3" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 3 0b10001L + +let%test "left inherit 4" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 4 0b10001L + +let%test "left inherit 5" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 5 0b10001L + +let%test "left inherit 6" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 6 0b10001L + +let%test "left inherit 7" = + [" 10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 7 0b10001L + +let%test "left inherit 8" = + [" 10001L";"0b10001L";" 1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 8 0b10001L + +let%test "left inherit 9" = + [" 10001L";" 0b10001L";" 1_0001L";"0b1_0001L"] = + test_width left_inherit_configs 9 0b10001L + +let%test "left inherit 10" = + [" 10001L";" 0b10001L";" 1_0001L";" 0b1_0001L"] = + test_width left_inherit_configs 10 0b10001L + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 1 0b10001L + +let%test "right inherit 2" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 2 0b10001L + +let%test "right inherit 3" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 3 0b10001L + +let%test "right inherit 4" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 4 0b10001L + +let%test "right inherit 5" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 5 0b10001L + +let%test "right inherit 6" = + ["10001L";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 6 0b10001L + +let%test "right inherit 7" = + ["10001L ";"0b10001L";"1_0001L";"0b1_0001L"] = + test_width right_inherit_configs 7 0b10001L + +let%test "right inherit 8" = + ["10001L ";"0b10001L";"1_0001L ";"0b1_0001L"] = + test_width right_inherit_configs 8 0b10001L + +let%test "right inherit 9" = + ["10001L ";"0b10001L ";"1_0001L ";"0b1_0001L"] = + test_width right_inherit_configs 9 0b10001L + +let%test "right inherit 10" = + ["10001L ";"0b10001L ";"1_0001L ";"0b1_0001L "] = + test_width right_inherit_configs 10 0b10001L + +(** * Large printing *) + +let%test "zero inherit 17" = + ["0000000000110111L";"0b00000000110111L";"0_0000_0011_0111L";"0b0000_0011_0111L"] = + test_width zero_inherit_configs 17 0b110111L + +let%test "left inherit 17" = + [" 110111L";" 0b110111L";" 11_0111L";" 0b11_0111L"] = + test_width left_inherit_configs 17 0b110111L + +let%test "right inherit 16" = + ["110111L ";"0b110111L ";"11_0111L ";"0b11_0111L "] = + test_width right_inherit_configs 17 0b110111L + +(** * -1 printing *) + +let%test "zero inherit -1 1" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 1 (-1L) + +let%test "left inherit -1 1" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 1 (-1L) + +let%test "right inherit -1 1" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 1 (-1L) + +let%test "zero inherit -1 65" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 65 (-1L) + +let%test "left inherit -1 65" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 65 (-1L) + +let%test "right inherit -1 65" = + ["1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 65 (-1L) + +let%test "zero inherit -1 66" = + ["01111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 66 (-1L) + +let%test "left inherit -1 66" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 66 (-1L) + +let%test "right inherit -1 66" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 66 (-1L) + +let%test "zero inherit -1 67" = + ["001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 67 (-1L) + +let%test "left inherit -1 67" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 67 (-1L) + +let%test "right inherit -1 67" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 67 (-1L) + +let%test "zero inherit -1 68" = + ["0001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b01111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 68 (-1L) + +let%test "left inherit -1 68" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 68 (-1L) + +let%test "right inherit -1 68" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 68 (-1L) + +let%test "zero inherit -1 79" = + ["000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b0000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 79 (-1L) + +let%test "left inherit -1 79" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 79 (-1L) + +let%test "right inherit -1 79" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 79 (-1L) + +let%test "zero inherit -1 80" = + ["0000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b00000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 80 (-1L) + +let%test "left inherit -1 80" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 80 (-1L) + +let%test "right inherit -1 80" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 80 (-1L) + +let%test "zero inherit -1 81" = + ["00000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"01111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 81 (-1L) + +let%test "left inherit -1 81" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 81 (-1L) + +let%test "right inherit -1 81" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 81 (-1L) + +let%test "zero inherit -1 82" = + ["000000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b0000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 82 (-1L) + +let%test "left inherit -1 82" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 82 (-1L) + +let%test "right inherit -1 82" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width right_inherit_configs 82 (-1L) + +let%test "zero inherit -1 83" = + ["0000000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b00000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"00_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b01111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 83 (-1L) + +let%test "left inherit -1 83" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;" 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 83 (-1L) + +let%test "right inherit -1 83" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ] = + test_width right_inherit_configs 83 (-1L) + +let%test "zero inherit -1 84" = + ["00000000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"0b000000000000000001111111111111111111111111111111111111111111111111111111111111111L" + ;"000_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;"0b0_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width zero_inherit_configs 84 (-1L) + +let%test "left inherit -1 84" = + [" 1111111111111111111111111111111111111111111111111111111111111111L" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111L" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ;" 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L" + ] = + test_width left_inherit_configs 84 (-1L) + +let%test "right inherit -1 84" = + ["1111111111111111111111111111111111111111111111111111111111111111L " + ;"0b1111111111111111111111111111111111111111111111111111111111111111L " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L " + ] = + test_width right_inherit_configs 84 (-1L) diff --git a/test/large_native64.ml b/test/large_native64.ml new file mode 100644 index 0000000..9d4db6e --- /dev/null +++ b/test/large_native64.ml @@ -0,0 +1,682 @@ +open Pp_binary_ints.Nativeint + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Five printing *) + +let%test "one default" [@tags "64-bits-only"] = + "101n" [@tags "64-bits-only"] = + to_string 0b101n + +let%test "one default manual" [@tags "64-bits-only"] = + "101n" [@tags "64-bits-only"] = + to_string_with ~flags:default ~min_width:1 0b101n + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width zero_inherit_configs 1 0b101n + +let%test "zero inherit 2" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width zero_inherit_configs 2 0b101n + +let%test "zero inherit 3" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width zero_inherit_configs 3 0b101n + +let%test "zero inherit 4" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width zero_inherit_configs 4 0b101n + +let%test "zero inherit 5" [@tags "64-bits-only"] = + ["0101n" + ;"0b101n" + ;"0101n" + ;"0b101n" + ] = + test_width zero_inherit_configs 5 0b101n + +let%test "zero inherit 6" [@tags "64-bits-only"] = + ["00101n" + ;"0b101n" + ;"00101n" + ;"0b101n" + ] = + test_width zero_inherit_configs 6 0b101n + +let%test "zero inherit 7" [@tags "64-bits-only"] = + ["000101n" + ;"0b0101n" + ;"0_0101n" + ;"0b0101n"] = + test_width zero_inherit_configs 7 0b101n + +let%test "zero inherit 8" [@tags "64-bits-only"] = + ["0000101n" + ;"0b00101n" + ;"00_0101n" + ;"0b00101n"] = + test_width zero_inherit_configs 8 0b101n + +let%test "zero inherit 9" [@tags "64-bits-only"] = + ["00000101n" + ;"0b000101n" + ;"000_0101n" + ;"0b0_0101n"] = + test_width zero_inherit_configs 9 0b101n + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width left_inherit_configs 1 0b101n + +let%test "left inherit 2" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width left_inherit_configs 2 0b101n + +let%test "left inherit 3" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width left_inherit_configs 3 0b101n + +let%test "left inherit 4" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width left_inherit_configs 4 0b101n + +let%test "left inherit 5" [@tags "64-bits-only"] = + [" 101n";"0b101n";" 101n";"0b101n"] = + test_width left_inherit_configs 5 0b101n + +let%test "left inherit 6" [@tags "64-bits-only"] = + [" 101n";"0b101n";" 101n";"0b101n"] = + test_width left_inherit_configs 6 0b101n + +let%test "left inherit 7" [@tags "64-bits-only"] = + [" 101n";" 0b101n";" 101n";" 0b101n"] = + test_width left_inherit_configs 7 0b101n + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width right_inherit_configs 1 0b101n + +let%test "right inherit 2" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width right_inherit_configs 2 0b101n + +let%test "right inherit 3" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width right_inherit_configs 3 0b101n + +let%test "right inherit 4" [@tags "64-bits-only"] = + ["101n";"0b101n";"101n";"0b101n"] = + test_width right_inherit_configs 4 0b101n + +let%test "right inherit 5" [@tags "64-bits-only"] = + ["101n ";"0b101n";"101n ";"0b101n"] = + test_width right_inherit_configs 5 0b101n + +let%test "right inherit 6" [@tags "64-bits-only"] = + ["101n ";"0b101n";"101n ";"0b101n"] = + test_width right_inherit_configs 6 0b101n + +let%test "right inherit 7" [@tags "64-bits-only"] = + ["101n ";"0b101n ";"101n ";"0b101n "] = + test_width right_inherit_configs 7 0b101n + +(** * Eight printing *) + +let%test "one default" [@tags "64-bits-only"] = + "1000n" [@tags "64-bits-only"] = + to_string 0b1000n + +let%test "one default manual" [@tags "64-bits-only"] = + "1000n" [@tags "64-bits-only"] = + to_string_with ~flags:default ~min_width:1 0b1000n + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width zero_inherit_configs 1 0b1000n + +let%test "zero inherit 2" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width zero_inherit_configs 2 0b1000n + +let%test "zero inherit 3" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width zero_inherit_configs 3 0b1000n + +let%test "zero inherit 4" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width zero_inherit_configs 4 0b1000n + +let%test "zero inherit 5" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width zero_inherit_configs 5 0b1000n + +let%test "zero inherit 6" [@tags "64-bits-only"] = + ["01000n";"0b1000n";"01000n";"0b1000n"] = + test_width zero_inherit_configs 6 0b1000n + +let%test "zero inherit 7" [@tags "64-bits-only"] = + ["001000n";"0b1000n";"0_1000n";"0b1000n"] = + test_width zero_inherit_configs 7 0b1000n + +let%test "zero inherit 8" [@tags "64-bits-only"] = + ["0001000n";"0b01000n";"00_1000n";"0b01000n"] = + test_width zero_inherit_configs 8 0b1000n + +let%test "zero inherit 9" [@tags "64-bits-only"] = + ["00001000n";"0b001000n";"000_1000n";"0b0_1000n"] = + test_width zero_inherit_configs 9 0b1000n + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width left_inherit_configs 1 0b1000n + +let%test "left inherit 2" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width left_inherit_configs 2 0b1000n + +let%test "left inherit 3" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width left_inherit_configs 3 0b1000n + +let%test "left inherit 4" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width left_inherit_configs 4 0b1000n + +let%test "left inherit 5" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width left_inherit_configs 5 0b1000n + +let%test "left inherit 6" [@tags "64-bits-only"] = + [" 1000n";"0b1000n";" 1000n";"0b1000n"] = + test_width left_inherit_configs 6 0b1000n + +let%test "left inherit 7" [@tags "64-bits-only"] = + [" 1000n";"0b1000n";" 1000n";"0b1000n"] = + test_width left_inherit_configs 7 0b1000n + +let%test "left inherit 8" [@tags "64-bits-only"] = + [" 1000n";" 0b1000n";" 1000n";" 0b1000n"] = + test_width left_inherit_configs 8 0b1000n + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width right_inherit_configs 1 0b1000n + +let%test "right inherit 2" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width right_inherit_configs 2 0b1000n + +let%test "right inherit 3" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width right_inherit_configs 3 0b1000n + +let%test "right inherit 4" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width right_inherit_configs 4 0b1000n + +let%test "right inherit 5" [@tags "64-bits-only"] = + ["1000n";"0b1000n";"1000n";"0b1000n"] = + test_width right_inherit_configs 5 0b1000n + +let%test "right inherit 6" [@tags "64-bits-only"] = + ["1000n ";"0b1000n";"1000n ";"0b1000n"] = + test_width right_inherit_configs 6 0b1000n + +let%test "right inherit 7" [@tags "64-bits-only"] = + ["1000n ";"0b1000n";"1000n ";"0b1000n"] = + test_width right_inherit_configs 7 0b1000n + +let%test "right inherit 8" [@tags "64-bits-only"] = + ["1000n ";"0b1000n ";"1000n ";"0b1000n "] = + test_width right_inherit_configs 8 0b1000n + +(** * Seventeen printing *) + +let%test "one default" [@tags "64-bits-only"] = + "10001n" [@tags "64-bits-only"] = + to_string 0b10001n + +let%test "one default manual" [@tags "64-bits-only"] = + "10001n" [@tags "64-bits-only"] = + to_string_with ~flags:default ~min_width:1 0b10001n + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 1 0b10001n + +let%test "zero inherit 2" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 2 0b10001n + +let%test "zero inherit 3" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 3 0b10001n + +let%test "zero inherit 4" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 4 0b10001n + +let%test "zero inherit 5" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 5 0b10001n + +let%test "zero inherit 6" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 6 0b10001n + +let%test "zero inherit 7" [@tags "64-bits-only"] = + ["010001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 7 0b10001n + +let%test "zero inherit 8" [@tags "64-bits-only"] = + ["0010001n";"0b10001n";"01_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 8 0b10001n + +let%test "zero inherit 9" [@tags "64-bits-only"] = + ["00010001n";"0b010001n";"001_0001n";"0b1_0001n"] = + test_width zero_inherit_configs 9 0b10001n + +let%test "zero inherit 10" [@tags "64-bits-only"] = + ["000010001n" + ;"0b0010001n" + ;"0001_0001n" + ;"0b01_0001n"] = + test_width zero_inherit_configs 10 0b10001n + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 1 0b10001n + +let%test "left inherit 2" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 2 0b10001n + +let%test "left inherit 3" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 3 0b10001n + +let%test "left inherit 4" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 4 0b10001n + +let%test "left inherit 5" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 5 0b10001n + +let%test "left inherit 6" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 6 0b10001n + +let%test "left inherit 7" [@tags "64-bits-only"] = + [" 10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 7 0b10001n + +let%test "left inherit 8" [@tags "64-bits-only"] = + [" 10001n";"0b10001n";" 1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 8 0b10001n + +let%test "left inherit 9" [@tags "64-bits-only"] = + [" 10001n";" 0b10001n";" 1_0001n";"0b1_0001n"] = + test_width left_inherit_configs 9 0b10001n + +let%test "left inherit 10" [@tags "64-bits-only"] = + [" 10001n";" 0b10001n";" 1_0001n";" 0b1_0001n"] = + test_width left_inherit_configs 10 0b10001n + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 1 0b10001n + +let%test "right inherit 2" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 2 0b10001n + +let%test "right inherit 3" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 3 0b10001n + +let%test "right inherit 4" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 4 0b10001n + +let%test "right inherit 5" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 5 0b10001n + +let%test "right inherit 6" [@tags "64-bits-only"] = + ["10001n";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 6 0b10001n + +let%test "right inherit 7" [@tags "64-bits-only"] = + ["10001n ";"0b10001n";"1_0001n";"0b1_0001n"] = + test_width right_inherit_configs 7 0b10001n + +let%test "right inherit 8" [@tags "64-bits-only"] = + ["10001n ";"0b10001n";"1_0001n ";"0b1_0001n"] = + test_width right_inherit_configs 8 0b10001n + +let%test "right inherit 9" [@tags "64-bits-only"] = + ["10001n ";"0b10001n ";"1_0001n ";"0b1_0001n"] = + test_width right_inherit_configs 9 0b10001n + +let%test "right inherit 10" [@tags "64-bits-only"] = + ["10001n ";"0b10001n ";"1_0001n ";"0b1_0001n "] = + test_width right_inherit_configs 10 0b10001n + +(** * Large printing *) + +let%test "zero inherit 17" [@tags "64-bits-only"] = + ["0000000000110111n";"0b00000000110111n";"0_0000_0011_0111n";"0b0000_0011_0111n"] = + test_width zero_inherit_configs 17 0b110111n + +let%test "left inherit 17" [@tags "64-bits-only"] = + [" 110111n";" 0b110111n";" 11_0111n";" 0b11_0111n"] = + test_width left_inherit_configs 17 0b110111n + +let%test "right inherit 16" [@tags "64-bits-only"] = + ["110111n ";"0b110111n ";"11_0111n ";"0b11_0111n "] = + test_width right_inherit_configs 17 0b110111n + +(** * -1 printing *) + +let%test "zero inherit -1 1" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 1 (-1n) + +let%test "left inherit -1 1" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 1 (-1n) + +let%test "right inherit -1 1" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 1 (-1n) + +let%test "zero inherit -1 65" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 65 (-1n) + +let%test "left inherit -1 65" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 65 (-1n) + +let%test "right inherit -1 65" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 65 (-1n) + +let%test "zero inherit -1 66" [@tags "64-bits-only"] = + ["01111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 66 (-1n) + +let%test "left inherit -1 66" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 66 (-1n) + +let%test "right inherit -1 66" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 66 (-1n) + +let%test "zero inherit -1 67" [@tags "64-bits-only"] = + ["001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 67 (-1n) + +let%test "left inherit -1 67" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 67 (-1n) + +let%test "right inherit -1 67" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 67 (-1n) + +let%test "zero inherit -1 68" [@tags "64-bits-only"] = + ["0001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b01111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 68 (-1n) + +let%test "left inherit -1 68" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 68 (-1n) + +let%test "right inherit -1 68" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 68 (-1n) + +let%test "zero inherit -1 79" [@tags "64-bits-only"] = + ["000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b0000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 79 (-1n) + +let%test "left inherit -1 79" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 79 (-1n) + +let%test "right inherit -1 79" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 79 (-1n) + +let%test "zero inherit -1 80" [@tags "64-bits-only"] = + ["0000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b00000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 80 (-1n) + +let%test "left inherit -1 80" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 80 (-1n) + +let%test "right inherit -1 80" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 80 (-1n) + +let%test "zero inherit -1 81" [@tags "64-bits-only"] = + ["00000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"01111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 81 (-1n) + +let%test "left inherit -1 81" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 81 (-1n) + +let%test "right inherit -1 81" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 81 (-1n) + +let%test "zero inherit -1 82" [@tags "64-bits-only"] = + ["000000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b0000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 82 (-1n) + +let%test "left inherit -1 82" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 82 (-1n) + +let%test "right inherit -1 82" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width right_inherit_configs 82 (-1n) + +let%test "zero inherit -1 83" [@tags "64-bits-only"] = + ["0000000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b00000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"00_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b01111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 83 (-1n) + +let%test "left inherit -1 83" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;" 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 83 (-1n) + +let%test "right inherit -1 83" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ] = + test_width right_inherit_configs 83 (-1n) + +let%test "zero inherit -1 84" [@tags "64-bits-only"] = + ["00000000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"0b000000000000000001111111111111111111111111111111111111111111111111111111111111111n" + ;"000_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;"0b0_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width zero_inherit_configs 84 (-1n) + +let%test "left inherit -1 84" [@tags "64-bits-only"] = + [" 1111111111111111111111111111111111111111111111111111111111111111n" + ;" 0b1111111111111111111111111111111111111111111111111111111111111111n" + ;" 1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ;" 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n" + ] = + test_width left_inherit_configs 84 (-1n) + +let%test "right inherit -1 84" [@tags "64-bits-only"] = + ["1111111111111111111111111111111111111111111111111111111111111111n " + ;"0b1111111111111111111111111111111111111111111111111111111111111111n " + ;"1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ;"0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111n " + ] = + test_width right_inherit_configs 84 (-1n) diff --git a/test/ones_int32.ml b/test/ones_int32.ml new file mode 100644 index 0000000..da02dea --- /dev/null +++ b/test/ones_int32.ml @@ -0,0 +1,205 @@ +open Pp_binary_ints.Int32 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * One printing *) + +let%test "one default" = + "1l" = + to_string 1l + +let%test "one default manual" = + "1l" = + to_string_with ~flags:default ~min_width:1 1l + +(** ** Zero Padding, OCaml *) + +let%test "zero ocaml 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width zero_ocaml_configs 1 1l + +let%test "zero ocaml 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width zero_ocaml_configs 2 1l + +let%test "zero ocaml 3" = + ["01l";"0b1l";"01l";"0b1l"] = + test_width zero_ocaml_configs 3 1l + +let%test "zero ocaml 4" = + ["001l";"0b1l";"001l";"0b1l"] = + test_width zero_ocaml_configs 4 1l + +let%test "zero ocaml 5" = + ["0001l";"0b01l";"0001l";"0b01l"] = + test_width zero_ocaml_configs 5 1l + +let%test "zero ocaml 6" = + ["00001l";"0b001l";"00001l";"0b001l"] = + test_width zero_ocaml_configs 6 1l + +let%test "zero ocaml 7" = + ["000001l";"0b0001l";"0_0001l";"0b0001l"] = + test_width zero_ocaml_configs 7 1l + +let%test "zero ocaml 8" = + ["0000001l";"0b00001l";"00_0001l";"0b00001l"] = + test_width zero_ocaml_configs 8 1l + +let%test "zero ocaml 9" = + ["00000001l";"0b000001l";"000_0001l";"0b0_0001l"] = + test_width zero_ocaml_configs 9 1l + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width left_ocaml_configs 1 1l + +let%test "left ocaml 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width left_ocaml_configs 2 1l + +let%test "left ocaml 3" = + [" 1l";"0b1l";" 1l";"0b1l"] = + test_width left_ocaml_configs 3 1l + +let%test "left ocaml 4" = + [" 1l";"0b1l";" 1l";"0b1l"] = + test_width left_ocaml_configs 4 1l + +let%test "left ocaml 5" = + [" 1l";" 0b1l";" 1l";" 0b1l"] = + test_width left_ocaml_configs 5 1l + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width right_ocaml_configs 1 1l + +let%test "right ocaml 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width right_ocaml_configs 2 1l + +let%test "right ocaml 3" = + ["1l ";"0b1l";"1l ";"0b1l"] = + test_width right_ocaml_configs 3 1l + +let%test "right ocaml 4" = + ["1l ";"0b1l";"1l ";"0b1l"] = + test_width right_ocaml_configs 4 1l + +let%test "right ocaml 5" = + ["1l ";"0b1l ";"1l ";"0b1l "] = + test_width right_ocaml_configs 5 1l + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width zero_inherit_configs 1 1l + +let%test "zero inherit 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width zero_inherit_configs 2 1l + +let%test "zero inherit 3" = + ["01l";"0b1l";"01l";"0b1l"] = + test_width zero_inherit_configs 3 1l + +let%test "zero inherit 4" = + ["001l";"0b1l";"001l";"0b1l"] = + test_width zero_inherit_configs 4 1l + +let%test "zero inherit 5" = + ["0001l";"0b01l";"0001l";"0b01l"] = + test_width zero_inherit_configs 5 1l + +let%test "zero inherit 6" = + ["00001l";"0b001l";"00001l";"0b001l"] = + test_width zero_inherit_configs 6 1l + +let%test "zero inherit 7" = + ["000001l";"0b0001l";"0_0001l";"0b0001l"] = + test_width zero_inherit_configs 7 1l + +let%test "zero inherit 8" = + ["0000001l";"0b00001l";"00_0001l";"0b00001l"] = + test_width zero_inherit_configs 8 1l + +let%test "zero inherit 9" = + ["00000001l";"0b000001l";"000_0001l";"0b0_0001l"] = + test_width zero_inherit_configs 9 1l + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width left_inherit_configs 1 1l + +let%test "left inherit 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width left_inherit_configs 2 1l + +let%test "left inherit 3" = + [" 1l";"0b1l";" 1l";"0b1l"] = + test_width left_inherit_configs 3 1l + +let%test "left inherit 4" = + [" 1l";"0b1l";" 1l";"0b1l"] = + test_width left_inherit_configs 4 1l + +let%test "left inherit 5" = + [" 1l";" 0b1l";" 1l";" 0b1l"] = + test_width left_inherit_configs 5 1l + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width right_inherit_configs 1 1l + +let%test "right inherit 2" = + ["1l";"0b1l";"1l";"0b1l"] = + test_width right_inherit_configs 2 1l + +let%test "right inherit 3" = + ["1l ";"0b1l";"1l ";"0b1l"] = + test_width right_inherit_configs 3 1l + +let%test "right inherit 4" = + ["1l ";"0b1l";"1l ";"0b1l"] = + test_width right_inherit_configs 4 1l + +let%test "right inherit 5" = + ["1l ";"0b1l ";"1l ";"0b1l "] = + test_width right_inherit_configs 5 1l diff --git a/test/ones_int64.ml b/test/ones_int64.ml new file mode 100644 index 0000000..703083b --- /dev/null +++ b/test/ones_int64.ml @@ -0,0 +1,205 @@ +open Pp_binary_ints.Int64 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * One printing *) + +let%test "one default" = + "1L" = + to_string 1L + +let%test "one default manual" = + "1L" = + to_string_with ~flags:default ~min_width:1 1L + +(** ** Zero Padding, OCaml *) + +let%test "zero ocaml 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width zero_ocaml_configs 1 1L + +let%test "zero ocaml 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width zero_ocaml_configs 2 1L + +let%test "zero ocaml 3" = + ["01L";"0b1L";"01L";"0b1L"] = + test_width zero_ocaml_configs 3 1L + +let%test "zero ocaml 4" = + ["001L";"0b1L";"001L";"0b1L"] = + test_width zero_ocaml_configs 4 1L + +let%test "zero ocaml 5" = + ["0001L";"0b01L";"0001L";"0b01L"] = + test_width zero_ocaml_configs 5 1L + +let%test "zero ocaml 6" = + ["00001L";"0b001L";"00001L";"0b001L"] = + test_width zero_ocaml_configs 6 1L + +let%test "zero ocaml 7" = + ["000001L";"0b0001L";"0_0001L";"0b0001L"] = + test_width zero_ocaml_configs 7 1L + +let%test "zero ocaml 8" = + ["0000001L";"0b00001L";"00_0001L";"0b00001L"] = + test_width zero_ocaml_configs 8 1L + +let%test "zero ocaml 9" = + ["00000001L";"0b000001L";"000_0001L";"0b0_0001L"] = + test_width zero_ocaml_configs 9 1L + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width left_ocaml_configs 1 1L + +let%test "left ocaml 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width left_ocaml_configs 2 1L + +let%test "left ocaml 3" = + [" 1L";"0b1L";" 1L";"0b1L"] = + test_width left_ocaml_configs 3 1L + +let%test "left ocaml 4" = + [" 1L";"0b1L";" 1L";"0b1L"] = + test_width left_ocaml_configs 4 1L + +let%test "left ocaml 5" = + [" 1L";" 0b1L";" 1L";" 0b1L"] = + test_width left_ocaml_configs 5 1L + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width right_ocaml_configs 1 1L + +let%test "right ocaml 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width right_ocaml_configs 2 1L + +let%test "right ocaml 3" = + ["1L ";"0b1L";"1L ";"0b1L"] = + test_width right_ocaml_configs 3 1L + +let%test "right ocaml 4" = + ["1L ";"0b1L";"1L ";"0b1L"] = + test_width right_ocaml_configs 4 1L + +let%test "right ocaml 5" = + ["1L ";"0b1L ";"1L ";"0b1L "] = + test_width right_ocaml_configs 5 1L + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width zero_inherit_configs 1 1L + +let%test "zero inherit 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width zero_inherit_configs 2 1L + +let%test "zero inherit 3" = + ["01L";"0b1L";"01L";"0b1L"] = + test_width zero_inherit_configs 3 1L + +let%test "zero inherit 4" = + ["001L";"0b1L";"001L";"0b1L"] = + test_width zero_inherit_configs 4 1L + +let%test "zero inherit 5" = + ["0001L";"0b01L";"0001L";"0b01L"] = + test_width zero_inherit_configs 5 1L + +let%test "zero inherit 6" = + ["00001L";"0b001L";"00001L";"0b001L"] = + test_width zero_inherit_configs 6 1L + +let%test "zero inherit 7" = + ["000001L";"0b0001L";"0_0001L";"0b0001L"] = + test_width zero_inherit_configs 7 1L + +let%test "zero inherit 8" = + ["0000001L";"0b00001L";"00_0001L";"0b00001L"] = + test_width zero_inherit_configs 8 1L + +let%test "zero inherit 9" = + ["00000001L";"0b000001L";"000_0001L";"0b0_0001L"] = + test_width zero_inherit_configs 9 1L + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width left_inherit_configs 1 1L + +let%test "left inherit 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width left_inherit_configs 2 1L + +let%test "left inherit 3" = + [" 1L";"0b1L";" 1L";"0b1L"] = + test_width left_inherit_configs 3 1L + +let%test "left inherit 4" = + [" 1L";"0b1L";" 1L";"0b1L"] = + test_width left_inherit_configs 4 1L + +let%test "left inherit 5" = + [" 1L";" 0b1L";" 1L";" 0b1L"] = + test_width left_inherit_configs 5 1L + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width right_inherit_configs 1 1L + +let%test "right inherit 2" = + ["1L";"0b1L";"1L";"0b1L"] = + test_width right_inherit_configs 2 1L + +let%test "right inherit 3" = + ["1L ";"0b1L";"1L ";"0b1L"] = + test_width right_inherit_configs 3 1L + +let%test "right inherit 4" = + ["1L ";"0b1L";"1L ";"0b1L"] = + test_width right_inherit_configs 4 1L + +let%test "right inherit 5" = + ["1L ";"0b1L ";"1L ";"0b1L "] = + test_width right_inherit_configs 5 1L diff --git a/test/ones_native.ml b/test/ones_native.ml new file mode 100644 index 0000000..afcec35 --- /dev/null +++ b/test/ones_native.ml @@ -0,0 +1,205 @@ +open Pp_binary_ints.Nativeint + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * One printing *) + +let%test "one default" = + "1n" = + to_string 1n + +let%test "one default manual" = + "1n" = + to_string_with ~flags:default ~min_width:1 1n + +(** ** Zero Padding, OCaml *) + +let%test "zero ocaml 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width zero_ocaml_configs 1 1n + +let%test "zero ocaml 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width zero_ocaml_configs 2 1n + +let%test "zero ocaml 3" = + ["01n";"0b1n";"01n";"0b1n"] = + test_width zero_ocaml_configs 3 1n + +let%test "zero ocaml 4" = + ["001n";"0b1n";"001n";"0b1n"] = + test_width zero_ocaml_configs 4 1n + +let%test "zero ocaml 5" = + ["0001n";"0b01n";"0001n";"0b01n"] = + test_width zero_ocaml_configs 5 1n + +let%test "zero ocaml 6" = + ["00001n";"0b001n";"00001n";"0b001n"] = + test_width zero_ocaml_configs 6 1n + +let%test "zero ocaml 7" = + ["000001n";"0b0001n";"0_0001n";"0b0001n"] = + test_width zero_ocaml_configs 7 1n + +let%test "zero ocaml 8" = + ["0000001n";"0b00001n";"00_0001n";"0b00001n"] = + test_width zero_ocaml_configs 8 1n + +let%test "zero ocaml 9" = + ["00000001n";"0b000001n";"000_0001n";"0b0_0001n"] = + test_width zero_ocaml_configs 9 1n + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width left_ocaml_configs 1 1n + +let%test "left ocaml 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width left_ocaml_configs 2 1n + +let%test "left ocaml 3" = + [" 1n";"0b1n";" 1n";"0b1n"] = + test_width left_ocaml_configs 3 1n + +let%test "left ocaml 4" = + [" 1n";"0b1n";" 1n";"0b1n"] = + test_width left_ocaml_configs 4 1n + +let%test "left ocaml 5" = + [" 1n";" 0b1n";" 1n";" 0b1n"] = + test_width left_ocaml_configs 5 1n + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width right_ocaml_configs 1 1n + +let%test "right ocaml 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width right_ocaml_configs 2 1n + +let%test "right ocaml 3" = + ["1n ";"0b1n";"1n ";"0b1n"] = + test_width right_ocaml_configs 3 1n + +let%test "right ocaml 4" = + ["1n ";"0b1n";"1n ";"0b1n"] = + test_width right_ocaml_configs 4 1n + +let%test "right ocaml 5" = + ["1n ";"0b1n ";"1n ";"0b1n "] = + test_width right_ocaml_configs 5 1n + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width zero_inherit_configs 1 1n + +let%test "zero inherit 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width zero_inherit_configs 2 1n + +let%test "zero inherit 3" = + ["01n";"0b1n";"01n";"0b1n"] = + test_width zero_inherit_configs 3 1n + +let%test "zero inherit 4" = + ["001n";"0b1n";"001n";"0b1n"] = + test_width zero_inherit_configs 4 1n + +let%test "zero inherit 5" = + ["0001n";"0b01n";"0001n";"0b01n"] = + test_width zero_inherit_configs 5 1n + +let%test "zero inherit 6" = + ["00001n";"0b001n";"00001n";"0b001n"] = + test_width zero_inherit_configs 6 1n + +let%test "zero inherit 7" = + ["000001n";"0b0001n";"0_0001n";"0b0001n"] = + test_width zero_inherit_configs 7 1n + +let%test "zero inherit 8" = + ["0000001n";"0b00001n";"00_0001n";"0b00001n"] = + test_width zero_inherit_configs 8 1n + +let%test "zero inherit 9" = + ["00000001n";"0b000001n";"000_0001n";"0b0_0001n"] = + test_width zero_inherit_configs 9 1n + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width left_inherit_configs 1 1n + +let%test "left inherit 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width left_inherit_configs 2 1n + +let%test "left inherit 3" = + [" 1n";"0b1n";" 1n";"0b1n"] = + test_width left_inherit_configs 3 1n + +let%test "left inherit 4" = + [" 1n";"0b1n";" 1n";"0b1n"] = + test_width left_inherit_configs 4 1n + +let%test "left inherit 5" = + [" 1n";" 0b1n";" 1n";" 0b1n"] = + test_width left_inherit_configs 5 1n + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width right_inherit_configs 1 1n + +let%test "right inherit 2" = + ["1n";"0b1n";"1n";"0b1n"] = + test_width right_inherit_configs 2 1n + +let%test "right inherit 3" = + ["1n ";"0b1n";"1n ";"0b1n"] = + test_width right_inherit_configs 3 1n + +let%test "right inherit 4" = + ["1n ";"0b1n";"1n ";"0b1n"] = + test_width right_inherit_configs 4 1n + +let%test "right inherit 5" = + ["1n ";"0b1n ";"1n ";"0b1n "] = + test_width right_inherit_configs 5 1n diff --git a/test/zeros.ml b/test/zeros.ml index 7169078..9cf6ee5 100644 --- a/test/zeros.ml +++ b/test/zeros.ml @@ -42,6 +42,8 @@ let%test "zero default manual" = (** ** Zero Padding, OCaml *) +(** OCaml's [Printf] does not prefix zeros *) + let%test "zero ocaml 1" = ["0";"0";"0";"0"] = test_width zero_ocaml_configs 1 0 @@ -62,6 +64,18 @@ let%test "zero ocaml 5" = ["00000";"00000";"00000";"00000"] = test_width zero_ocaml_configs 5 0 +let%test "zero ocaml 6" = + ["000000";"000000";"0_0000";"0_0000"] = + test_width zero_ocaml_configs 6 0 + +let%test "zero ocaml 16" = + ["0000000000000000" + ;"0000000000000000" + ;"0_0000_0000_0000" + ;"0_0000_0000_0000" + ] = + test_width zero_ocaml_configs 16 0 + (** ** Left Padding, OCaml *) let%test "left ocaml 1" = diff --git a/test/zeros_int32.ml b/test/zeros_int32.ml new file mode 100644 index 0000000..8b3122c --- /dev/null +++ b/test/zeros_int32.ml @@ -0,0 +1,215 @@ +open Pp_binary_ints.Int32 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Zero printing *) + +let%test "zero default" = + "0l" = + to_string 0l + +let%test "zero default manual" = + "0l" = + to_string_with ~flags:default ~min_width:1 0l + +(** ** Zero Padding, OCaml *) + +(** OCaml's [Printf] does not prefix zeros *) + +let%test "zero ocaml 1" = + ["0l";"0l";"0l";"0l"] = + test_width zero_ocaml_configs 1 0l + +let%test "zero ocaml 2" = + ["0l";"0l";"0l";"0l"] = + test_width zero_ocaml_configs 2 0l + +let%test "zero ocaml 3" = + ["00l";"00l";"00l";"00l"] = + test_width zero_ocaml_configs 3 0l + +let%test "zero ocaml 4" = + ["000l";"000l";"000l";"000l"] = + test_width zero_ocaml_configs 4 0l + +let%test "zero ocaml 5" = + ["0000l";"0000l";"0000l";"0000l"] = + test_width zero_ocaml_configs 5 0l + +let%test "zero ocaml 6" = + ["00000l";"00000l";"00000l";"00000l"] = + test_width zero_ocaml_configs 6 0l + +let%test "zero ocaml 7" = + ["000000l";"000000l";"0_0000l";"0_0000l"] = + test_width zero_ocaml_configs 7 0l + +let%test "zero ocaml 16" = + ["000000000000000l" + ;"000000000000000l" + ;"00000_0000_0000l" + ;"00000_0000_0000l" + ] = + test_width zero_ocaml_configs 16 0l + +let%test "zero ocaml 17" = + ["0000000000000000l" + ;"0000000000000000l" + ;"0_0000_0000_0000l" + ;"0_0000_0000_0000l" + ] = + test_width zero_ocaml_configs 17 0l + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["0l";"0l";"0l";"0l"] = + test_width left_ocaml_configs 1 0l + +let%test "left ocaml 2" = + ["0l";"0l";"0l";"0l"] = + test_width left_ocaml_configs 2 0l + +let%test "left ocaml 3" = + [" 0l";" 0l";" 0l";" 0l"] = + test_width left_ocaml_configs 3 0l + +let%test "left ocaml 4" = + [" 0l";" 0l";" 0l";" 0l"] = + test_width left_ocaml_configs 4 0l + +let%test "left ocaml 5" = + [" 0l";" 0l";" 0l";" 0l"] = + test_width left_ocaml_configs 5 0l + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["0l";"0l";"0l";"0l"] = + test_width right_ocaml_configs 1 0l + +let%test "right ocaml 2" = + ["0l";"0l";"0l";"0l"] = + test_width right_ocaml_configs 2 0l + +let%test "right ocaml 3" = + ["0l ";"0l ";"0l ";"0l "] = + test_width right_ocaml_configs 3 0l + +let%test "right ocaml 4" = + ["0l ";"0l ";"0l ";"0l "] = + test_width right_ocaml_configs 4 0l + +let%test "right ocaml 5" = + ["0l ";"0l ";"0l ";"0l "] = + test_width right_ocaml_configs 5 0l + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width zero_inherit_configs 1 0l + +let%test "zero inherit 2" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width zero_inherit_configs 2 0l + +let%test "zero inherit 3" = + ["00l";"0b0l";"00l";"0b0l"] = + test_width zero_inherit_configs 3 0l + +let%test "zero inherit 4" = + ["000l";"0b0l";"000l";"0b0l"] = + test_width zero_inherit_configs 4 0l + +let%test "zero inherit 5" = + ["0000l";"0b00l";"0000l";"0b00l"] = + test_width zero_inherit_configs 5 0l + +let%test "zero inherit 6" = + ["00000l";"0b000l";"00000l";"0b000l"] = + test_width zero_inherit_configs 6 0l + +let%test "zero inherit 7" = + ["000000l";"0b0000l";"0_0000l";"0b0000l"] = + test_width zero_inherit_configs 7 0l + +let%test "zero inherit 8" = + ["0000000l";"0b00000l";"00_0000l";"0b00000l"] = + test_width zero_inherit_configs 8 0l + +let%test "zero inherit 9" = + ["00000000l";"0b000000l";"000_0000l";"0b0_0000l"] = + test_width zero_inherit_configs 9 0l + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width left_inherit_configs 1 0l + +let%test "left inherit 2" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width left_inherit_configs 2 0l + +let%test "left inherit 3" = + [" 0l";"0b0l";" 0l";"0b0l"] = + test_width left_inherit_configs 3 0l + +let%test "left inherit 4" = + [" 0l";"0b0l";" 0l";"0b0l"] = + test_width left_inherit_configs 4 0l + +let%test "left inherit 5" = + [" 0l";" 0b0l";" 0l";" 0b0l"] = + test_width left_inherit_configs 5 0l + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width right_inherit_configs 1 0l + +let%test "right inherit 2" = + ["0l";"0b0l";"0l";"0b0l"] = + test_width right_inherit_configs 2 0l + +let%test "right inherit 3" = + ["0l ";"0b0l";"0l ";"0b0l"] = + test_width right_inherit_configs 3 0l + +let%test "right inherit 4" = + ["0l ";"0b0l";"0l ";"0b0l"] = + test_width right_inherit_configs 4 0l + +let%test "right inherit 5" = + ["0l ";"0b0l ";"0l ";"0b0l "] = + test_width right_inherit_configs 5 0l diff --git a/test/zeros_int64.ml b/test/zeros_int64.ml new file mode 100644 index 0000000..9f54fb7 --- /dev/null +++ b/test/zeros_int64.ml @@ -0,0 +1,223 @@ +open Pp_binary_ints.Int64 + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Zero printing *) + +let%test "zero default" = + "0L" = + to_string 0L + +let%test "zero default manual" = + "0L" = + to_string_with ~flags:default ~min_width:1 0L + +(** ** Zero Padding, OCaml *) + +(** OCaml's [Printf] does not prefix zeros *) + +let%test "zero ocaml 1" = + ["0L";"0L";"0L";"0L"] = + test_width zero_ocaml_configs 1 0L + +let%test "zero ocaml 2" = + ["0L";"0L";"0L";"0L"] = + test_width zero_ocaml_configs 2 0L + +let%test "zero ocaml 3" = + ["00L";"00L";"00L";"00L"] = + test_width zero_ocaml_configs 3 0L + +let%test "zero ocaml 4" = + ["000L";"000L";"000L";"000L"] = + test_width zero_ocaml_configs 4 0L + +let%test "zero ocaml 5" = + ["0000L";"0000L";"0000L";"0000L"] = + test_width zero_ocaml_configs 5 0L + +let%test "zero ocaml 6" = + ["00000L";"00000L";"00000L";"00000L"] = + test_width zero_ocaml_configs 6 0L + +let%test "zero ocaml 7" = + ["000000L";"000000L";"0_0000L";"0_0000L"] = + test_width zero_ocaml_configs 7 0L + +let%test "zero ocaml 16" = + ["000000000000000L" + ;"000000000000000L" + ;"00000_0000_0000L" + ;"00000_0000_0000L" + ] = + test_width zero_ocaml_configs 16 0L + +let%test "zero ocaml 17" = + ["0000000000000000L" + ;"0000000000000000L" + ;"0_0000_0000_0000L" + ;"0_0000_0000_0000L" + ] = + test_width zero_ocaml_configs 17 0L + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["0L";"0L";"0L";"0L"] = + test_width left_ocaml_configs 1 0L + +let%test "left ocaml 2" = + ["0L";"0L";"0L";"0L"] = + test_width left_ocaml_configs 2 0L + +let%test "left ocaml 3" = + [" 0L";" 0L";" 0L";" 0L"] = + test_width left_ocaml_configs 3 0L + +let%test "left ocaml 4" = + [" 0L";" 0L";" 0L";" 0L"] = + test_width left_ocaml_configs 4 0L + +let%test "left ocaml 5" = + [" 0L";" 0L";" 0L";" 0L"] = + test_width left_ocaml_configs 5 0L + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["0L";"0L";"0L";"0L"] = + test_width right_ocaml_configs 1 0L + +let%test "right ocaml 2" = + ["0L";"0L";"0L";"0L"] = + test_width right_ocaml_configs 2 0L + +let%test "right ocaml 3" = + ["0L ";"0L ";"0L ";"0L "] = + test_width right_ocaml_configs 3 0L + +let%test "right ocaml 4" = + ["0L ";"0L ";"0L ";"0L "] = + test_width right_ocaml_configs 4 0L + +let%test "right ocaml 5" = + ["0L ";"0L ";"0L ";"0L "] = + test_width right_ocaml_configs 5 0L + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width zero_inherit_configs 1 0L + +let%test "zero inherit 2" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width zero_inherit_configs 2 0L + +let%test "zero inherit 3" = + ["00L";"0b0L";"00L";"0b0L"] = + test_width zero_inherit_configs 3 0L + +let%test "zero inherit 4" = + ["000L";"0b0L";"000L";"0b0L"] = + test_width zero_inherit_configs 4 0L + +let%test "zero inherit 5" = + ["0000L";"0b00L";"0000L";"0b00L"] = + test_width zero_inherit_configs 5 0L + +let%test "zero inherit 6" = + ["00000L";"0b000L";"00000L";"0b000L"] = + test_width zero_inherit_configs 6 0L + +let%test "zero inherit 7" = + ["000000L";"0b0000L";"0_0000L";"0b0000L"] = + test_width zero_inherit_configs 7 0L + +let%test "zero inherit 8" = + ["0000000L";"0b00000L";"00_0000L";"0b00000L"] = + test_width zero_inherit_configs 8 0L + +let%test "zero inherit 9" = + ["00000000L";"0b000000L";"000_0000L";"0b0_0000L"] = + test_width zero_inherit_configs 9 0L + +let%test "zero inherit 16" = + ["000000000000000L" + ;"0b0000000000000L" + ;"00000_0000_0000L" + ;"0b000_0000_0000L" + ] = + test_width zero_inherit_configs 16 0L + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width left_inherit_configs 1 0L + +let%test "left inherit 2" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width left_inherit_configs 2 0L + +let%test "left inherit 3" = + [" 0L";"0b0L";" 0L";"0b0L"] = + test_width left_inherit_configs 3 0L + +let%test "left inherit 4" = + [" 0L";"0b0L";" 0L";"0b0L"] = + test_width left_inherit_configs 4 0L + +let%test "left inherit 5" = + [" 0L";" 0b0L";" 0L";" 0b0L"] = + test_width left_inherit_configs 5 0L + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width right_inherit_configs 1 0L + +let%test "right inherit 2" = + ["0L";"0b0L";"0L";"0b0L"] = + test_width right_inherit_configs 2 0L + +let%test "right inherit 3" = + ["0L ";"0b0L";"0L ";"0b0L"] = + test_width right_inherit_configs 3 0L + +let%test "right inherit 4" = + ["0L ";"0b0L";"0L ";"0b0L"] = + test_width right_inherit_configs 4 0L + +let%test "right inherit 5" = + ["0L ";"0b0L ";"0L ";"0b0L "] = + test_width right_inherit_configs 5 0L diff --git a/test/zeros_native.ml b/test/zeros_native.ml new file mode 100644 index 0000000..fe5b658 --- /dev/null +++ b/test/zeros_native.ml @@ -0,0 +1,223 @@ +open Pp_binary_ints.Nativeint + +open Pp_binary_ints.Flags + +let configs = + [ { default with separators = false; prefix_non_zero = false } + ; { default with separators = false; prefix_non_zero = true } + ; { default with separators = true; prefix_non_zero = false } + ; { default with separators = true; prefix_non_zero = true } + ] + +let zero_ocaml_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = OCaml }) configs + +let left_ocaml_configs = + List.map (fun x -> { x with padding = Left; zero_printing = OCaml }) configs + +let right_ocaml_configs = + List.map (fun x -> { x with padding = Right; zero_printing = OCaml }) configs + +let zero_inherit_configs = + List.map (fun x -> { x with padding = Zeros; zero_printing = InheritNonZero }) configs + +let left_inherit_configs = + List.map (fun x -> { x with padding = Left; zero_printing = InheritNonZero }) configs + +let right_inherit_configs = + List.map (fun x -> { x with padding = Right; zero_printing = InheritNonZero }) configs + +let test_width configs min_width n : string list = + List.map (fun flags -> to_string_with ~flags ~min_width n) configs + +(** * Zero printing *) + +let%test "zero default" = + "0n" = + to_string 0n + +let%test "zero default manual" = + "0n" = + to_string_with ~flags:default ~min_width:1 0n + +(** ** Zero Padding, OCaml *) + +(** OCaml's [Printf] does not prefix zeros *) + +let%test "zero ocaml 1" = + ["0n";"0n";"0n";"0n"] = + test_width zero_ocaml_configs 1 0n + +let%test "zero ocaml 2" = + ["0n";"0n";"0n";"0n"] = + test_width zero_ocaml_configs 2 0n + +let%test "zero ocaml 3" = + ["00n";"00n";"00n";"00n"] = + test_width zero_ocaml_configs 3 0n + +let%test "zero ocaml 4" = + ["000n";"000n";"000n";"000n"] = + test_width zero_ocaml_configs 4 0n + +let%test "zero ocaml 5" = + ["0000n";"0000n";"0000n";"0000n"] = + test_width zero_ocaml_configs 5 0n + +let%test "zero ocaml 6" = + ["00000n";"00000n";"00000n";"00000n"] = + test_width zero_ocaml_configs 6 0n + +let%test "zero ocaml 7" = + ["000000n";"000000n";"0_0000n";"0_0000n"] = + test_width zero_ocaml_configs 7 0n + +let%test "zero ocaml 16" = + ["000000000000000n" + ;"000000000000000n" + ;"00000_0000_0000n" + ;"00000_0000_0000n" + ] = + test_width zero_ocaml_configs 16 0n + +let%test "zero ocaml 17" = + ["0000000000000000n" + ;"0000000000000000n" + ;"0_0000_0000_0000n" + ;"0_0000_0000_0000n" + ] = + test_width zero_ocaml_configs 17 0n + +(** ** Left Padding, OCaml *) + +let%test "left ocaml 1" = + ["0n";"0n";"0n";"0n"] = + test_width left_ocaml_configs 1 0n + +let%test "left ocaml 2" = + ["0n";"0n";"0n";"0n"] = + test_width left_ocaml_configs 2 0n + +let%test "left ocaml 3" = + [" 0n";" 0n";" 0n";" 0n"] = + test_width left_ocaml_configs 3 0n + +let%test "left ocaml 4" = + [" 0n";" 0n";" 0n";" 0n"] = + test_width left_ocaml_configs 4 0n + +let%test "left ocaml 5" = + [" 0n";" 0n";" 0n";" 0n"] = + test_width left_ocaml_configs 5 0n + +(** ** Right Padding, OCaml *) + +let%test "right ocaml 1" = + ["0n";"0n";"0n";"0n"] = + test_width right_ocaml_configs 1 0n + +let%test "right ocaml 2" = + ["0n";"0n";"0n";"0n"] = + test_width right_ocaml_configs 2 0n + +let%test "right ocaml 3" = + ["0n ";"0n ";"0n ";"0n "] = + test_width right_ocaml_configs 3 0n + +let%test "right ocaml 4" = + ["0n ";"0n ";"0n ";"0n "] = + test_width right_ocaml_configs 4 0n + +let%test "right ocaml 5" = + ["0n ";"0n ";"0n ";"0n "] = + test_width right_ocaml_configs 5 0n + +(** ** Zero Padding, Inherit *) + +let%test "zero inherit 1" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width zero_inherit_configs 1 0n + +let%test "zero inherit 2" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width zero_inherit_configs 2 0n + +let%test "zero inherit 3" = + ["00n";"0b0n";"00n";"0b0n"] = + test_width zero_inherit_configs 3 0n + +let%test "zero inherit 4" = + ["000n";"0b0n";"000n";"0b0n"] = + test_width zero_inherit_configs 4 0n + +let%test "zero inherit 5" = + ["0000n";"0b00n";"0000n";"0b00n"] = + test_width zero_inherit_configs 5 0n + +let%test "zero inherit 6" = + ["00000n";"0b000n";"00000n";"0b000n"] = + test_width zero_inherit_configs 6 0n + +let%test "zero inherit 7" = + ["000000n";"0b0000n";"0_0000n";"0b0000n"] = + test_width zero_inherit_configs 7 0n + +let%test "zero inherit 8" = + ["0000000n";"0b00000n";"00_0000n";"0b00000n"] = + test_width zero_inherit_configs 8 0n + +let%test "zero inherit 9" = + ["00000000n";"0b000000n";"000_0000n";"0b0_0000n"] = + test_width zero_inherit_configs 9 0n + +let%test "zero inherit 16" = + ["000000000000000n" + ;"0b0000000000000n" + ;"00000_0000_0000n" + ;"0b000_0000_0000n" + ] = + test_width zero_inherit_configs 16 0n + +(** ** Left Padding, Inherit *) + +let%test "left inherit 1" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width left_inherit_configs 1 0n + +let%test "left inherit 2" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width left_inherit_configs 2 0n + +let%test "left inherit 3" = + [" 0n";"0b0n";" 0n";"0b0n"] = + test_width left_inherit_configs 3 0n + +let%test "left inherit 4" = + [" 0n";"0b0n";" 0n";"0b0n"] = + test_width left_inherit_configs 4 0n + +let%test "left inherit 5" = + [" 0n";" 0b0n";" 0n";" 0b0n"] = + test_width left_inherit_configs 5 0n + +(** ** Right Padding, Inherit *) + +let%test "right inherit 1" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width right_inherit_configs 1 0n + +let%test "right inherit 2" = + ["0n";"0b0n";"0n";"0b0n"] = + test_width right_inherit_configs 2 0n + +let%test "right inherit 3" = + ["0n ";"0b0n";"0n ";"0b0n"] = + test_width right_inherit_configs 3 0n + +let%test "right inherit 4" = + ["0n ";"0b0n";"0n ";"0b0n"] = + test_width right_inherit_configs 4 0n + +let%test "right inherit 5" = + ["0n ";"0b0n ";"0n ";"0b0n "] = + test_width right_inherit_configs 5 0n