forked from janestreet/sexplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
223 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ OASISFormat: 0.3 | |
OCamlVersion: >= 4.00.0 | ||
FindlibVersion: >= 1.3.2 | ||
Name: sexplib | ||
Version: 109.53.00 | ||
Version: 109.55.00 | ||
Synopsis: sexplib - automated S-expression conversion | ||
Authors: Jane Street Capital LLC <[email protected]> | ||
Copyrights: (C) 2005-2013 Jane Street Capital LLC <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
------ simple atom ------ | ||
mach: | ||
line1 | ||
hum: | ||
line1 | ||
|
||
------ one trailing newline ------ | ||
mach: | ||
"line1\n" | ||
hum: | ||
"line1\n" | ||
|
||
------ two lines ------ | ||
mach: | ||
"line1\nline2" | ||
hum: | ||
"line1\ | ||
\nline2" | ||
|
||
------ two lines and trailing newline ------ | ||
mach: | ||
"line1\nline2\n" | ||
hum: | ||
"line1\ | ||
\nline2\ | ||
\n" | ||
|
||
------ two lines, windows style ------ | ||
mach: | ||
"line1\r\nline2" | ||
hum: | ||
"line1\r\ | ||
\nline2" | ||
|
||
------ two lines and trailing windows style ------ | ||
mach: | ||
"line1\r\nline2\r\n" | ||
hum: | ||
"line1\r\ | ||
\nline2\r\ | ||
\n" | ||
|
||
------ two lines inside of parens ------ | ||
mach: | ||
("line1\nline2") | ||
hum: | ||
( "line1\ | ||
\nline2") | ||
|
||
------ many lines and indentation in the atom ------ | ||
mach: | ||
"line1\n line2\n line3\n line4\n" | ||
hum: | ||
"line1\ | ||
\n line2\ | ||
\n line3\ | ||
\n line4\ | ||
\n" | ||
|
||
------ indentation with tabs in the atom ------ | ||
mach: | ||
"line1\n\tline2\n\t\tline3\n\t\t\tline4\n" | ||
hum: | ||
"line1\ | ||
\n\tline2\ | ||
\n\t\tline3\ | ||
\n\t\t\tline4\ | ||
\n" | ||
|
||
------ trailing whitespace ------ | ||
mach: | ||
(("line1 \n line3 \n ")) | ||
hum: | ||
(( "line1 \ | ||
\n line3 \ | ||
\n ")) | ||
|
||
------ catalog snapshot ------ | ||
mach: | ||
" cancel-buy\n | cancel-sell\n | | local-buy\n | | | local-cancel-buy\n | | | | local-cancel-sell\n | | | | | local-sell\nINDEX buy | | | | | | sell\n| | | | | | | | |\ntest_sym1 10. 10. 9.\ntest_sym3 \n" | ||
hum: | ||
" cancel-buy\ | ||
\n | cancel-sell\ | ||
\n | | local-buy\ | ||
\n | | | local-cancel-buy\ | ||
\n | | | | local-cancel-sell\ | ||
\n | | | | | local-sell\ | ||
\nINDEX buy | | | | | | sell\ | ||
\n| | | | | | | | |\ | ||
\ntest_sym1 10. 10. 9.\ | ||
\ntest_sym3 \ | ||
\n" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
open StdLabels | ||
open Sexplib | ||
|
||
let windowsify_newlines str = | ||
let b = Buffer.create (String.length str * 2) in | ||
for i = 0 to String.length str - 1; do | ||
match str.[i] with | ||
| '\n' -> Buffer.add_string b "\r\n" | ||
| c -> Buffer.add_char b c | ||
done; | ||
Buffer.contents b | ||
|
||
let () = | ||
List.iter [ | ||
"simple atom", Sexp.Atom "line1"; | ||
"one trailing newline", Sexp.Atom "line1\n"; | ||
"two lines", Sexp.Atom "line1\nline2"; | ||
"two lines and trailing newline", Sexp.Atom "line1\nline2\n"; | ||
"two lines, windows style", Sexp.Atom "line1\r\nline2"; | ||
"two lines and trailing windows style", Sexp.Atom "line1\r\nline2\r\n"; | ||
"two lines inside of parens", Sexp.of_string "(\"line1\nline2\")"; | ||
"many lines and indentation in the atom", Sexp.Atom "line1\n line2\n line3\n line4\n"; | ||
"indentation with tabs in the atom", Sexp.Atom "line1\n\tline2\n\t\tline3\n\t\t\tline4\n"; | ||
"trailing whitespace", Sexp.List [Sexp.List [Sexp.Atom "line1 \n line3 \n "]]; | ||
"catalog snapshot", Sexp.Atom " cancel-buy\n | cancel-sell\n | | local-buy\n | | | local-cancel-buy\n | | | | local-cancel-sell\n | | | | | local-sell\nINDEX buy | | | | | | sell\n| | | | | | | | |\ntest_sym1 10. 10. 9.\ntest_sym3 \n"; | ||
] ~f:(fun (title, sexp) -> | ||
(* My understanding of newlines on windows is that in memory, a newline is a \n, but | ||
when writing to a file with a file handler open in text mode, all the \n are | ||
replaced with \r\n. Of course the conversion is undone when reading with a file | ||
handler open in text mode. If saving \n in text-mode and reading it in binary mode, | ||
we would receive \r\n back. | ||
I am testing that serializing + writing in text mode + reading in binary mode + | ||
deserializing is the identity (because it was before this newline printing stuff), | ||
and all the other cases should just work. *) | ||
let reparsed = Sexp.of_string (Sexp.to_string_hum sexp) in | ||
let reparsed_after_windows_fiddling = | ||
Sexp.of_string (windowsify_newlines (Sexp.to_string_hum sexp)) | ||
in | ||
let reparsing_result = | ||
if reparsed <> sexp then | ||
Printf.sprintf "to_string_hum + of_string + to_mach is NOT the identity:\n%s\n" | ||
(Sexp.to_string_mach reparsed) | ||
else "" | ||
in | ||
let reparsing_after_windows_fiddling_result = | ||
if reparsed_after_windows_fiddling <> sexp then | ||
Printf.sprintf "to_string_hum + windowsify + of_string + to_mach is NOT the identity:\n%s\n" | ||
(Sexp.to_string_mach reparsed_after_windows_fiddling) | ||
else "" | ||
in | ||
Printf.printf "------ %s ------\nmach:\n%s\nhum:\n%s\n%s%s\n" | ||
title | ||
(Sexp.to_string_mach sexp) | ||
(Sexp.to_string_hum sexp) | ||
reparsing_result reparsing_after_windows_fiddling_result | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters