[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/aptel/dynamic-modules-rc3 9dc8a56 9/9: modules/yam
From: |
Teodor Zlatanov |
Subject: |
[Emacs-diffs] feature/aptel/dynamic-modules-rc3 9dc8a56 9/9: modules/yaml/test.el: implement deep equal + remainging tests |
Date: |
Tue, 10 Feb 2015 14:53:58 +0000 |
branch: feature/aptel/dynamic-modules-rc3
commit 9dc8a56a4dc27a752186185743c4fc16c8fced45
Author: Aurélien Aptel <address@hidden>
Commit: Aurélien Aptel <address@hidden>
modules/yaml/test.el: implement deep equal + remainging tests
---
modules/yaml/test.el | 104 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 84 insertions(+), 20 deletions(-)
diff --git a/modules/yaml/test.el b/modules/yaml/test.el
index b0082c3..80d6600 100644
--- a/modules/yaml/test.el
+++ b/modules/yaml/test.el
@@ -1,33 +1,33 @@
(require 'ert)
+(require 'cl)
(require 'yaml)
(ert-deftest yaml-scalar ()
"Tests scalar parsing"
- (should (equal '("abc")
- (yaml-parse-string
- "---
+ (should (yaml-equal '("abc")
+ (yaml-parse-string
+ "---
abc
"))))
(ert-deftest yaml-sequence ()
"Tests sequence parsing"
- (should (equal '(("abc" "def" "ghi" "jkl"))
- (yaml-parse-string
- "---
+ (should (yaml-equal '(("abc" "def" "ghi" "jkl"))
+ (yaml-parse-string
+ "---
- abc
- def
- ghi
- jkl
"))))
-;; TODO: need deep equal for hash-tables for the rest
-
(ert-deftest yaml-map ()
"Tests map parsing"
- (skip-unless nil) ;; TODO
- (should (equal 'xxx
- (yaml-parse-string
- "---
+ (should (yaml-equal '(#s(hash-table data ("a" "1"
+ "b" "2"
+ "c" "3")))
+ (yaml-parse-string
+ "---
a: 1
b: 2
c: 3
@@ -35,10 +35,16 @@ c: 3
(ert-deftest yaml-multi-doc ()
"Tests documents parsing"
- (skip-unless nil) ;; TODO
- (should (equal 'xxx
- (yaml-parse-string
- "---
+ (should (yaml-equal
+ '(#s(hash-table data ("a" "1"
+ "b" ("1" "2" "3")))
+ #s(hash-table data ("foo" #s(hash-table data ("bar" "1"
+ "baz" "2"
+ "bad" "3"))
+ "zob" ("42" "43")))
+ "abc")
+ (yaml-parse-string
+ "---
a: 1
b:
- 1
@@ -58,10 +64,36 @@ abc
(ert-deftest yaml-alias ()
"Tests alias parsing"
- (skip-unless nil) ;; TODO
- (should (equal 'xxx
- (yaml-parse-string
- "---
+ (should (yaml-equal
+ '(#s(hash-table
+ data
+ ("invoice" "34843"
+ "date" "2001-01-23"
+ "bill-to"
+ #s(hash-table
+ data
+ ("given" "Chris"
+ "family" "Dumars"
+ "address"
+ #s(hash-table
+ data
+ ("lines" "458 Walkman Dr.\nSuite #292\n"
+ "city" "Royal Oak"
+ "state" "MI"
+ "postal" "48046"))))
+ "ship-to" #s(hash-table
+ data
+ ("given" "Chris"
+ "family" "Dumars"
+ "address"
+ #s(hash-table
+ data
+ ("lines" "458 Walkman Dr.\nSuite #292\n"
+ "city" "Royal Oak"
+ "state" "MI"
+ "postal" "48046")))))))
+ (yaml-parse-string
+ "---
invoice: 34843
date : 2001-01-23
bill-to: &id001
@@ -76,3 +108,35 @@ bill-to: &id001
postal : 48046
ship-to: *id001
"))))
+
+(defun yaml-equal (a b)
+ "Basic, slow, deep equal that supports hash-tables. No circular stuff, no
optimizations, nothing."
+ (and
+ (eq (type-of a) (type-of b))
+ (or
+ (eq a b)
+ (and (number-or-marker-p a) (= a b))
+ (and (stringp a) (string= a b))
+ (and (sequencep a)
+ (let ((la (length a))
+ (lb (length b))
+ (res t))
+ (and (= la lb)
+ (catch 'ret
+ (dotimes (i la t)
+ (when (null (yaml-equal (elt a i) (elt b i)))
+ (throw 'ret nil)))))))
+ (and (hash-table-p a)
+ (let ((h1 a)
+ (h2 b))
+ (and (hash-table-p h1) (hash-table-p h2)
+ (equal (hash-table-count h1) (hash-table-count h2))
+ ;;(equal (hash-table-weakness h1) (hash-table-weakness h2))
+ ;;(equal (hash-table-rehash-threshold h1)
(hash-table-rehash-threshold h2))
+ (loop as notfound = (gensym)
+ for k being the hash-keys of h1
+ as v1 = (gethash k h1 notfound)
+ as v2 = (gethash k h2 notfound)
+ if (or (eq h1 notfound) (eq h2 notfound) (not
(yaml-equal v1 v2)))
+ return nil
+ finally return t)))))))
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 updated (9a1d734 -> 9dc8a56), Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 6e9c6b1 1/9: doc.c: fix module doc prefix, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 b82611b 2/9: modules/tests.py: honnor module list from args, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 4257b6b 3/9: lread.c: update load-module docstring, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 3a2aab6 4/9: modules/fmod: use M prefix for module global vars, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 2e998a7 5/9: modules/fmod: use right docstring in test, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 ef45794 7/9: modules/yaml: skip TODO tests, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 f52bd1f 6/9: modules: prefix all global module variable with M, Teodor Zlatanov, 2015/02/10
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9dc8a56 9/9: modules/yaml/test.el: implement deep equal + remainging tests,
Teodor Zlatanov <=
- [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9461927 8/9: modules/opaque/test.el: use `should' macro instead of assert, Teodor Zlatanov, 2015/02/10