Test_Build

Provides unit tests and examples for the Build lens.

Summary
Test_BuildProvides unit tests and examples for the Build lens.
GENERIC CONSTRUCTIONS
bracketsTest brackets
brackets
LIST CONSTRUCTIONS
list
list
list
opt_list
opt_list
LABEL OPERATIONS
xchg
xchg
xchgs
xchgs
SUBNODE CONSTRUCTIONS
key_value_line
key_value_line
key_value_line_comment
key_value_line_comment
key_value
key_value
key_ws_value
key_ws_value
flag
flag
flag_line
flag_line
BLOCK CONSTRUCTIONS
block_entryThe block entry used for testing
blockThe block used for testing
blockSimple test for block
blockSimple test for block with newlines
blockSimple test for block two indented entries
blockTest block with a comment
blockTest block with comments and newlines
blockTest defaults for blocks
named_blockThe named block used for testing
named_blockSimple test for named_block
logrotate_blockA minimalistic logrotate block
logrotate_block

GENERIC CONSTRUCTIONS

brackets

let brackets = [ Build.brackets Sep.lbracket Sep.rbracket (key Rx.word) ]

Test brackets

brackets

test brackets get "(foo)" = { "foo" }

LIST CONSTRUCTIONS

list

let list = Build.list [ key Rx.word ] Sep.space

list

test list get "foo bar baz" = { "foo" } { "bar" } { "baz" }

list

test list get "foo" = *

opt_list

let opt_list = Build.opt_list [ key Rx.word ] Sep.space

opt_list

test opt_list get "foo bar baz" = { "foo" } { "bar" } { "baz" }

LABEL OPERATIONS

xchg

let xchg = [ Build.xchg Rx.space " " "space" ]

xchg

test xchg get " \t " = { "space" }

xchgs

let xchgs = [ Build.xchgs " " "space" ]

xchgs

test xchgs get " " = { "space" }

SUBNODE CONSTRUCTIONS

key_value_line

let key_value_line = Build.key_value_line Rx.word Sep.equal (store Rx.word)

key_value_line

test key_value_line get "foo=bar\n" = { "foo" = "bar" }

key_value_line_comment

let key_value_line_comment = Build.key_value_line_comment Rx.word Sep.equal (store Rx.word) Util.comment

key_value_line_comment

test key_value_line_comment get "foo=bar # comment\n" = { "foo" = "bar" { "#comment" = "comment" } }

key_value

let key_value = Build.key_value Rx.word Sep.equal (store Rx.word)

key_value

test key_value get "foo=bar" = { "foo" = "bar" }

key_ws_value

let key_ws_value = Build.key_ws_value Rx.word

key_ws_value

test key_ws_value get "foo bar\n" = { "foo" = "bar" }

flag

let flag = Build.flag Rx.word

flag

test flag get "foo" = { "foo" }

flag_line

let flag_line = Build.flag_line Rx.word

flag_line

test flag_line get "foo\n" = { "foo" }

BLOCK CONSTRUCTIONS

block_entry

let block_entry = Build.key_value "test" Sep.equal (store Rx.word)

The block entry used for testing

block

let block = Build.block block_entry

The block used for testing

block

test block get " {test=1}" = { "test" = "1" }

Simple test for block

block

test block get " {\n test=1\n}" = { "test" = "1" }

Simple test for block with newlines

block

test block get " {\n test=1 \n test=2 \n}" = { "test" = "1" } { "test" = "2" }

Simple test for block two indented entries

block

test block get " { # This is a comment\n}" = { "#comment" = "This is a comment" }

Test block with a comment

block

test block get " { # This is a comment\n# Another comment\n}" = { "#comment" = "This is a comment" } { "#comment" = "Another comment" }

Test block with comments and newlines

block

test block put " { test=1 }" after set "/#comment" "a comment"; rm "/

Test defaults for blocks

named_block

let named_block = Build.named_block "foo" block_entry

The named block used for testing

named_block

test named_block get "foo {test=1}\n" = { "foo" { "test" = "1" } }

Simple test for named_block

logrotate_block

let logrotate_block = let entry = [ key Rx.word ] in let filename = [ label "file" . store /\/[^,#= \n\t{}]+/ ] in let filename_sep = del /[ \t\n]+/ " " in let filenames = Build.opt_list filename filename_sep in [ label "rule" . filenames . Build.block entry ]

A minimalistic logrotate block

logrotate_block

test logrotate_block get "/var/log/wtmp\n/var/log/wtmp2\n{ missingok monthly }" = { "rule" { "file" = "/var/log/wtmp" } { "file" = "/var/log/wtmp2" } { "missingok" } { "monthly" } }
Generic functions to build lenses
let brackets = [ Build.brackets Sep.lbracket Sep.rbracket (key Rx.word) ]
Test brackets
let list = Build.list [ key Rx.word ] Sep.space
let opt_list = Build.opt_list [ key Rx.word ] Sep.space
let xchg = [ Build.xchg Rx.space " " "space" ]
let xchgs = [ Build.xchgs " " "space" ]
let key_value_line = Build.key_value_line Rx.word Sep.equal (store Rx.word)
let key_value_line_comment = Build.key_value_line_comment Rx.word Sep.equal (store Rx.word) Util.comment
let key_value = Build.key_value Rx.word Sep.equal (store Rx.word)
let key_ws_value = Build.key_ws_value Rx.word
let flag = Build.flag Rx.word
let flag_line = Build.flag_line Rx.word
let block_entry = Build.key_value "test" Sep.equal (store Rx.word)
The block entry used for testing
let block = Build.block block_entry
The block used for testing
let named_block = Build.named_block "foo" block_entry
The named block used for testing
let logrotate_block = let entry = [ key Rx.word ] in let filename = [ label "file" . store /\/[^,#= \n\t{}]+/ ] in let filename_sep = del /[ \t\n]+/ " " in let filenames = Build.opt_list filename filename_sep in [ label "rule" . filenames . Build.block entry ]
A minimalistic logrotate block
Close