Skip to content

Commit

Permalink
Add Quote.dquote_spaces and Quote.squote_spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Dec 12, 2012
1 parent 869a483 commit 62473fd
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lenses/quote.aug
Expand Up @@ -124,3 +124,22 @@ let quote_spaces (lns:lens) =
in let quoted = Quote.do_quote (store /[^"' \t\n]*[ \t][^"' \t\n]*/)
in [ lns . bare ] | [ lns . quoted ]

(* View: dquote_spaces
Make double quotes mandatory if value contains spaces,
and optional if value doesn't contain spaces. *)
let dquote_spaces (lns:lens) =
(* bare has no spaces, and is optionally quoted *)
let bare = Quote.do_dquote_opt (store /[^" \t\n]+/)
(* quoted has at least one space, and must be quoted *)
in let quoted = Quote.do_dquote (store /[^" \t\n]*[ \t][^" \t\n]*/)
in [ lns . bare ] | [ lns . quoted ]

(* View: squote_spaces
Make single quotes mandatory if value contains spaces,
and optional if value doesn't contain spaces. *)
let squote_spaces (lns:lens) =
(* bare has no spaces, and is optionally quoted *)
let bare = Quote.do_squote_opt (store /[^' \t\n]+/)
(* quoted has at least one space, and must be quoted *)
in let quoted = Quote.do_squote (store /[^' \t\n]*[ \t][^' \t\n]*/)
in [ lns . bare ] | [ lns . quoted ]
116 changes: 116 additions & 0 deletions lenses/tests/test_quote.aug
Expand Up @@ -152,3 +152,119 @@ test quote_spaces put "\"this\""
test quote_spaces put "'this'"
after set "spc" "this that" =
"'this that'"

(* Group: dquote_spaces *)

(* View: dquote_spaces *)
let dquote_spaces =
Quote.dquote_spaces (label "spc")

(* Test: dquote_spaces
Unquoted value *)
test dquote_spaces get "this" =
{ "spc" = "this" }

(* Test: dquote_spaces
double quoted value *)
test dquote_spaces get "\"this\"" =
{ "spc" = "this" }

(* Test: dquote_spaces
single quoted value *)
test dquote_spaces get "'this'" =
{ "spc" = "'this'" }

(* Test: dquote_spaces
unquoted value with spaces *)
test dquote_spaces get "this that" = *

(* Test: dquote_spaces
double quoted value with spaces *)
test dquote_spaces get "\"this that\"" =
{ "spc" = "this that" }

(* Test: dquote_spaces
single quoted value with spaces *)
test dquote_spaces get "'this that'" = *

(* Test: dquote_spaces
remove spaces from double-quoted value *)
test dquote_spaces put "\"this that\""
after set "spc" "thisthat" =
"\"thisthat\""

(* Test: dquote_spaces
add spaces to unquoted value *)
test dquote_spaces put "this"
after set "spc" "this that" =
"\"this that\""

(* Test: dquote_spaces
add spaces to double-quoted value *)
test dquote_spaces put "\"this\""
after set "spc" "this that" =
"\"this that\""

(* Test: dquote_spaces
add spaces to single-quoted value *)
test dquote_spaces put "'this'"
after set "spc" "this that" =
"\"this that\""

(* Group: squote_spaces *)

(* View: squote_spaces *)
let squote_spaces =
Quote.squote_spaces (label "spc")

(* Test: squote_spaces
Unquoted value *)
test squote_spaces get "this" =
{ "spc" = "this" }

(* Test: squote_spaces
double quoted value *)
test squote_spaces get "\"this\"" =
{ "spc" = "\"this\"" }

(* Test: squote_spaces
single quoted value *)
test squote_spaces get "'this'" =
{ "spc" = "this" }

(* Test: squote_spaces
unquoted value with spaces *)
test squote_spaces get "this that" = *

(* Test: squote_spaces
double quoted value with spaces *)
test squote_spaces get "\"this that\"" = *

(* Test: squote_spaces
single quoted value with spaces *)
test squote_spaces get "'this that'" =
{ "spc" = "this that" }

(* Test: squote_spaces
remove spaces from single-quoted value *)
test squote_spaces put "'this that'"
after set "spc" "thisthat" =
"'thisthat'"

(* Test: squote_spaces
add spaces to unquoted value *)
test squote_spaces put "this"
after set "spc" "this that" =
"'this that'"

(* Test: squote_spaces
add spaces to double-quoted value *)
test squote_spaces put "\"this\""
after set "spc" "this that" =
"'this that'"

(* Test: squote_spaces
add spaces to single-quoted value *)
test squote_spaces put "'this'"
after set "spc" "this that" =
"'this that'"

0 comments on commit 62473fd

Please sign in to comment.