# Test_Build

Provides unit tests and examples for the Build lens.

Summary

Test_Build | Provides unit tests and examples for the Build lens.
GENERIC CONSTRUCTIONS |
brackets | Test 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_entry | The block entry used for testing
block | The block used for testing
block | Simple test for block
block | Simple test for block with newlines
block | Simple test for block two indented entries
block | Test block with a comment
block | Test block with comments and newlines
block | Test defaults for blocks
named_block | The named block used for testing
named_block | Simple test for named_block
logrotate_block | A minimalistic logrotate block
logrotate_block |
COMBINATORICS |
combine_two | A minimalistic combination lens
combine_two | Should parse ab
combine_two | Should parse ba
combine_two | Should not parse a
combine_two | Should not parse b
combine_two | Should not parse aa
combine_two | Should not parse bb
combine_two_opt | A minimalistic optional combination lens
combine_two_opt | Should parse ab
combine_two_opt | Should parse ba
combine_two_opt | Should parse a
combine_two_opt | Should parse b
combine_two_opt | Should not parse aa
combine_two_opt | Should not parse bb
combine_three | A minimalistic optional combination lens
combine_three | Should not parse ab
combine_three | Should not parse ba
combine_three | Should not parse a
combine_three | Should not parse b
combine_three | Should not parse aa
combine_three | Should not parse bbc
combine_three | Should parse abc
combine_three | Should parse cab
combine_three_opt | A minimalistic optional combination lens
combine_three_opt | Should parse ab
combine_three_opt | Should parse ba
combine_three_opt | Should parse a
combine_three_opt | Should parse b
combine_three_opt | Should not parse aa
combine_three_opt | Should not parse bbc
combine_three_opt | Should parse abc
combine_three_opt | Should parse cab

### 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" } }

### COMBINATORICS

### combine_two

> let combine_two = let entry (k:string) = [ key k ] in Build.combine_two (entry "a") (entry "b")

A minimalistic combination lens

### combine_two

> test combine_two get "ab" = { "a" } { "b" }

Should parse ab

### combine_two

> test combine_two get "ba" = { "b" } { "a" }

Should parse ba

### combine_two

> test combine_two get "a" = *

Should not parse a

### combine_two

> test combine_two get "b" = *

Should not parse b

### combine_two

> test combine_two get "aa" = *

Should not parse aa

### combine_two

> test combine_two get "bb" = *

Should not parse bb

### combine_two_opt

> let combine_two_opt = let entry (k:string) = [ key k ] in Build.combine_two_opt (entry "a") (entry "b")

A minimalistic optional combination lens

### combine_two_opt

> test combine_two_opt get "ab" = { "a" } { "b" }

Should parse ab

### combine_two_opt

> test combine_two_opt get "ba" = { "b" } { "a" }

Should parse ba

### combine_two_opt

> test combine_two_opt get "a" = { "a" }

Should parse a

### combine_two_opt

> test combine_two_opt get "b" = { "b" }

Should parse b

### combine_two_opt

> test combine_two_opt get "aa" = *

Should not parse aa

### combine_two_opt

> test combine_two_opt get "bb" = *

Should not parse bb

### combine_three

> let combine_three = let entry (k:string) = [ key k ] in Build.combine_three (entry "a") (entry "b") (entry "c")

A minimalistic optional combination lens

### combine_three

> test combine_three get "ab" = *

Should not parse ab

### combine_three

> test combine_three get "ba" = *

Should not parse ba

### combine_three

> test combine_three get "a" = *

Should not parse a

### combine_three

> test combine_three get "b" = *

Should not parse b

### combine_three

> test combine_three get "aa" = *

Should not parse aa

### combine_three

> test combine_three get "bbc" = *

Should not parse bbc

### combine_three

> test combine_three get "abc" = { "a" } { "b" } { "c" }

Should parse abc

### combine_three

> test combine_three get "cab" = { "c" } { "a" } { "b" }

Should parse cab

### combine_three_opt

> let combine_three_opt = let entry (k:string) = [ key k ] in Build.combine_three_opt (entry "a") (entry "b") (entry "c")

A minimalistic optional combination lens

### combine_three_opt

> test combine_three_opt get "ab" = { "a" } { "b" }

Should parse ab

### combine_three_opt

> test combine_three_opt get "ba" = { "b" } { "a" }

Should parse ba

### combine_three_opt

> test combine_three_opt get "a" = { "a" }

Should parse a

### combine_three_opt

> test combine_three_opt get "b" = { "b" }

Should parse b

### combine_three_opt

> test combine_three_opt get "aa" = *

Should not parse aa

### combine_three_opt

> test combine_three_opt get "bbc" = *

Should not parse bbc

### combine_three_opt

> test combine_three_opt get "abc" = { "a" } { "b" } { "c" }

Should parse abc

### combine_three_opt

> test combine_three_opt get "cab" = { "c" } { "a" } { "b" }

Should parse cab

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

> let combine_two = let entry (k:string) = [ key k ] in Build.combine_two (entry "a") (entry "b")

A minimalistic combination lens

> let combine_two_opt = let entry (k:string) = [ key k ] in Build.combine_two_opt (entry "a") (entry "b")

A minimalistic optional combination lens

> let combine_three = let entry (k:string) = [ key k ] in Build.combine_three (entry "a") (entry "b") (entry "c")

A minimalistic optional combination lens

> let combine_three_opt = let entry (k:string) = [ key k ] in Build.combine_three_opt (entry "a") (entry "b") (entry "c")

A minimalistic optional combination lens
Close