]> gitweb.factorcode.org Git - factor.git/commitdiff
resolv-conf: Parse edns0, refactor some words, and add a unit test.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 22 Mar 2019 03:52:17 +0000 (22:52 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 22 Mar 2019 03:53:01 +0000 (22:53 -0500)
extra/resolv-conf/resolv-conf-tests.factor [new file with mode: 0644]
extra/resolv-conf/resolv-conf.factor

diff --git a/extra/resolv-conf/resolv-conf-tests.factor b/extra/resolv-conf/resolv-conf-tests.factor
new file mode 100644 (file)
index 0000000..59c52cf
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (C) 2019 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test resolv-conf ;
+IN: resolv-conf.tests
+{
+    T{ resolv.conf
+        { nameserver V{ "127.0.0.53" } }
+        { domain V{ } }
+        { lookup V{ } }
+        { search V{ "localdomain" } }
+        { sortlist V{ } }
+        { options T{ options { edns0? t } } }
+    }
+} [
+    "nameserver 127.0.0.53
+    options edns0
+    search localdomain" string>resolv.conf
+] unit-test
\ No newline at end of file
index f5c098c8a821392a0b6f3fe6c9a4f9286e1c36d9..8a271e42eaa92e4123b526e3b62ab09d45d88dd8 100644 (file)
@@ -68,6 +68,7 @@ ERROR: unsupported-resolv.conf-option string ;
         { [ "rotate" ?head ] [ drop t >>rotate? ] }
         { [ "no-check-names" ?head ] [ drop t >>no-check-names? ] }
         { [ "inet6" ?head ] [ drop t >>inet6? ] }
+        { [ "edns0" ?head ] [ drop t >>edns0? ] }
         [ unsupported-resolv.conf-option ]
     } cond drop ;
 
@@ -86,12 +87,17 @@ ERROR: unsupported-resolv.conf-line string ;
 
 PRIVATE>
 
-: parse-resolve.conf ( path -- resolv.conf )
+: lines>resolv.conf ( lines -- resolv.conf )
     [ <resolv.conf> ] dip
-    utf8 file-lines
     [ [ blank? ] trim ] map harvest
     [ "#" head? ] reject
     [ parse-resolv.conf-line ] each ;
 
+: string>resolv.conf ( string -- resolv.conf )
+    string-lines lines>resolv.conf ;
+
+: path>resolv.conf ( path -- resolv.conf )
+    utf8 file-lines lines>resolv.conf ;
+
 : default-resolv.conf ( -- resolv.conf )
-    "/etc/resolv.conf" parse-resolve.conf ;
+    "/etc/resolv.conf" path>resolv.conf ;