emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 1da4344 32/60: Update url-str-parser


From: Junpeng Qiu
Subject: [elpa] master 1da4344 32/60: Update url-str-parser
Date: Tue, 25 Oct 2016 17:45:14 +0000 (UTC)

branch: master
commit 1da4344fbd1dd588ec03b841c39d3c204a12fe63
Author: Junpeng Qiu <address@hidden>
Commit: Junpeng Qiu <address@hidden>

    Update url-str-parser
---
 examples/url-str-parser-tests.el |   48 ++++++++++++++++++++++++++++++++++++++
 examples/url-str-parser.el       |   11 +++------
 2 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/examples/url-str-parser-tests.el b/examples/url-str-parser-tests.el
new file mode 100644
index 0000000..92bca94
--- /dev/null
+++ b/examples/url-str-parser-tests.el
@@ -0,0 +1,48 @@
+;;; url-str-parser-tests.el --- Tests for url-str-parser  -*- lexical-binding: 
t; -*-
+
+;; Copyright (C) 2016  Junpeng Qiu
+
+;; Author: Junpeng Qiu <address@hidden>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'url-str-parser)
+
+(ert-deftest test-url-str ()
+  (should
+   (equal
+    (url-str-parse "foo=bar&a%21=b+c")
+    '(("foo" Just . "bar")
+      ("a!" Just . "b c"))))
+  (should
+   (equal
+    (url-str-parse "foo=&a%21=b+c")
+    '(("foo" Just . "")
+      ("a!" Just . "b c"))))
+  (should
+   (equal
+    (url-str-parse "foo&a%21=b+c")
+    '(("foo" . Nothing)
+      ("a!" Just . "b c")))))
+
+(provide 'url-str-parser-tests)
+;;; url-str-parser-tests.el ends here
diff --git a/examples/url-str-parser.el b/examples/url-str-parser.el
index f08c2fd..926c6df 100644
--- a/examples/url-str-parser.el
+++ b/examples/url-str-parser.el
@@ -31,7 +31,8 @@
 (defun url-str-pair ()
   (cons
    (parsec-many1-as-string (url-str-char))
-   (parsec-make-maybe (parsec-and (parsec-ch ?=) (parsec-many-as-string 
(url-str-char))))))
+   (parsec-optional-maybe
+    (parsec-and (parsec-ch ?=) (parsec-many-as-string (url-str-char))))))
 
 (defun url-str-char ()
   (parsec-or (parsec-re "[a-zA-z0-9$_.!*'(),-]")
@@ -48,14 +49,8 @@
                              16))))
 
 (defun url-str-parse (input)
-  (with-temp-buffer
-    (insert input)
-    (goto-char (point-min))
+  (parsec-with-input input
     (url-str-query)))
 
-(url-str-parse "foo=bar&a%21=b+c")
-(url-str-parse "foo=&a%21=b+c")
-(url-str-parse "foo&a%21=b+c")
-
 (provide 'url-str-parser)
 ;;; url-str-parser.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]