From 893c76ad530ca0e81cd84602543c3114407f4592 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 9 Dec 2020 20:42:37 -0400 Subject: Added support for "Commons Clause" to Licentia. --- stdlib/source/test/licentia.lux | 121 ++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 49 deletions(-) (limited to 'stdlib/source/test/licentia.lux') diff --git a/stdlib/source/test/licentia.lux b/stdlib/source/test/licentia.lux index 92b43b20c..af03062cb 100644 --- a/stdlib/source/test/licentia.lux +++ b/stdlib/source/test/licentia.lux @@ -1,9 +1,12 @@ (.module: [lux #* - [cli (#+ program:)] ["_" test (#+ Test)] - [abstract/monad (#+ do)] - [io (#+ io)] + [abstract + [monad (#+ do)]] + [control + [io (#+ io)] + [parser + [cli (#+ program:)]]] [data ["." bit ("#\." equivalence)] ["." maybe ("#\." functor)] @@ -13,7 +16,7 @@ [collection ["." list ("#\." functor)]]] [math - ["r" random (#+ Random)]]] + ["." random (#+ Random)]]] {#program [/ ["." license (#+ Identification @@ -24,6 +27,7 @@ Extension Entity Black-List URL Attribution + Addendum License) ["." time (#+ Period)] ["." copyright] @@ -37,108 +41,117 @@ ["." commercial] ["." extension] ["." miscellaneous] - ["." black-list]] + ["." black-list] + ["." addendum]] ["." output]]}) (def: period (Random (Period Nat)) - (do {! r.monad} - [start (r.filter (|>> (n.= n\top) not) - r.nat) + (do {! random.monad} + [start (random.filter (|>> (n.= n\top) not) + random.nat) #let [wiggle-room (n.- start n\top)] end (\ ! map (|>> (n.% wiggle-room) (n.max 1)) - r.nat)] + random.nat)] (wrap {#time.start start #time.end end}))) (def: copyright-holder (Random copyright.Holder) - ($_ r.and - (r.ascii 10) + ($_ random.and + (random.ascii 10) ..period)) (def: identification (Random Identification) - ($_ r.and - (r.ascii 10) - (r.ascii 10))) + ($_ random.and + (random.ascii 10) + (random.ascii 10))) (def: termination (Random Termination) - ($_ r.and - r.bit - r.nat - r.nat)) + ($_ random.and + random.bit + random.nat + random.nat)) (def: liability (Random Liability) - ($_ r.and - r.bit - r.bit)) + ($_ random.and + random.bit + random.bit)) (def: distribution (Random Distribution) - ($_ r.and - r.bit - r.bit)) + ($_ random.and + random.bit + random.bit)) (def: commercial (Random Commercial) - ($_ r.and - r.bit - r.bit - r.bit)) + ($_ random.and + random.bit + random.bit + random.bit)) (def: extension (Random Extension) - ($_ r.and - r.bit - r.bit - (r.maybe ..period) - r.bit)) + ($_ random.and + random.bit + random.bit + (random.maybe ..period) + random.bit)) (def: entity (Random Entity) - (r.ascii 10)) + (random.ascii 10)) (def: (variable-list max-size gen-element) (All [a] (-> Nat (Random a) (Random (List a)))) - (do {! r.monad} + (do {! random.monad} [amount (\ ! map (n.% (n.max 1 max-size)) - r.nat)] - (r.list amount gen-element))) + random.nat)] + (random.list amount gen-element))) (def: black-list (Random Black-List) - ($_ r.and - (r.maybe (r.ascii 10)) + ($_ random.and + (random.maybe (random.ascii 10)) (variable-list 10 ..entity))) (def: url (Random URL) - (r.ascii 10)) + (random.ascii 10)) (def: attribution (Random Attribution) - ($_ r.and - (r.ascii 10) - (r.maybe (r.ascii 10)) + ($_ random.and + (random.ascii 10) + (random.maybe (random.ascii 10)) ..url - (r.maybe ..url))) + (random.maybe ..url))) + +(def: addendum + (Random Addendum) + ($_ random.and + random.bit + )) (def: license (Random License) - ($_ r.and - (r.list 2 ..copyright-holder) - (r.maybe ..identification) + ($_ random.and + (random.list 2 ..copyright-holder) + (random.maybe ..identification) ..termination ..liability ..distribution ..commercial ..extension (variable-list 3 ..black-list) - (r.maybe attribution))) + (random.maybe attribution) + ..addendum + )) (type: (Concern a) (-> (-> Text Bit) a Test)) @@ -263,9 +276,17 @@ (present? miscellaneous.export-restrictions)) )) +(def: (about-addendum present? value) + (Concern Addendum) + ($_ _.and + (_.test "Commons clause" + (bit\= (get@ #license.commons-clause? value) + (present? addendum.commons-clause))) + )) + (def: test Test - (do r.monad + (do random.monad [license ..license #let [writ (output.license license) present? (: (-> Text Bit) @@ -337,6 +358,8 @@ (..about-miscellaneous present?) + (..about-addendum present? (get@ #license.addendum license)) + (_.test "License ending footer is present." (present? notice.end-of-license)) ))) -- cgit v1.2.3