Commits

Anonymous committed f69b92e

added generator for ipv4 address

Comments (0)

Files changed (3)

data-generators-net.scm

+(module data-generators-net
+  (gen-ipv4-address)
+  (import chicken scheme)
+  (require-library data-generators srfi-13)
+  (import (only srfi-13 string-join))
+  (import (only data-generators gen-tuple-of gen-uint8 gen-transform))
+
+  (define (gen-ipv4-address)
+    (let ((octet-gen (gen-transform number->string (gen-uint8))))
+      (gen-transform (cut string-join <> ".") (gen-tuple-of octet-gen octet-gen octet-gen octet-gen)))))

data-generators.setup

  'data-generators-literals
  '("data-generators-literals.so" "data-generators-literals.import.so")
  `((version ,version)))
+
+(compile -d0 -O2 -J -s data-generators-net.scm)
+(compile -d0 -O2 -s data-generators-net.import.scm)
+
+(install-extension
+ 'data-generators-net
+  '("data-generators-net.so" "data-generators-net.import.so")
+   `((version ,version)))
 
-(use test)
+(use test irregex)
 
-(use data-generators numbers)
+(use data-generators data-generators-net numbers)
 
 (define (in? x ls) (not (null? (member x ls))))
 (define (all-in? list-of-values ls)
 (define (all-between? ls x y)
   (every (lambda (v) (between? v x y)) ls))
 
+(define (all-match? rx vals)
+  (every (lambda (v) (irregex-match rx v)) vals))
+
 (define (<-* gen)
   (<- 50 gen))
 
             (test-error "unsupported generator"
                         #g[#t .. #f]))
 
+
+(test-group "generators/net"
+            (test-group "gen-ipv4"
+                        (all-match? 'ipv4-address (<-* (gen-ipv4-address)))))
+
 (test-end "data-generators")
 
 (test-exit)