liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d49cbbb8edbe5209a6180ef90634cc7c8cd01598
parent 7683ed69de8b3de74d95a747e14d3530346bc9f9
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 11 Sep 2023 00:07:49 +0100

test for acquire-wan-address

Diffstat:
Aexamples/acquire-wan-address-test.fnl | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkgs/anoia/init.fnl | 5++++-
2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/examples/acquire-wan-address-test.fnl b/examples/acquire-wan-address-test.fnl @@ -0,0 +1,68 @@ +(local subject (require :acquire-wan-address)) +(local { : view } (require :fennel)) +(local { : merge : dup } (require :anoia)) + + +(local a1 + { + "2001-ab-cd-ef_hjgKHGhKJH" { + :address "2001:ab:cd:ef" + :len "64" + :preferred "200" + :valid "200" + } + } + ) + +(local a2 + { + "2001-0-1-2-3_aNteBnb" { + :address "2001:0:1:2:3" + :len "64" + :preferred "200" + :valid "200" + } + } + ) + +(macro expect [assertion] + (let [msg (.. "expectation failed: " (view assertion))] + `(when (not ,assertion) + (assert false ,msg)))) + +(fn first-address [] + (let [(add del) + (subject.changes + { } + a1 + )] + (expect (= (# del) 0)) + (expect (= (# add) 1)) + (let [[first] add] + (expect (= first.address "2001:ab:cd:ef"))))) + +(fn second-address [] + (let [(add del) + (subject.changes + a1 + (merge (dup a1) a2) + )] + (expect (= (# del) 0)) + (expect (= (# add) 1)) + (let [[first] add] (expect (= first.address "2001:0:1:2:3"))))) + +(fn less-address []1 + (let [(add del) + (subject.changes + (merge (dup a1) a2) + a1 + )] + (expect (= (# add) 0)) + (expect (= (# del) 1)) + + (let [[first] del] (expect (= first.address "2001:0:1:2:3"))))) + + +(first-address) +(second-address) +(less-address) diff --git a/pkgs/anoia/init.fnl b/pkgs/anoia/init.fnl @@ -2,6 +2,9 @@ (collect [k v (pairs table2) &into table1] k v)) +(fn dup [table] + (collect [k v (pairs table)] k v)) + (fn split [sep string] (icollect [v (string.gmatch string (.. "([^" sep "]+)"))] v)) @@ -56,4 +59,4 @@ (s:sub 1 (- (# s) pad)))) -{ : merge : split : file-exists? : system : hash : base64url } +{ : merge : split : file-exists? : system : hash : base64url : dup }