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

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

[elpa] 59/255: passing first two tests


From: Eric Schulte
Subject: [elpa] 59/255: passing first two tests
Date: Sun, 16 Mar 2014 01:02:19 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit 60753a5a854a03ee45fe8e836fff51b776113dfd
Author: Eric Schulte <address@hidden>
Date:   Tue May 22 10:33:19 2012 -0400

    passing first two tests
---
 sgf-tests.el |   29 ++++++++++-------------------
 sgf2el.el    |   30 ++++++++++++++++--------------
 2 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/sgf-tests.el b/sgf-tests.el
index 0f83016..4f65341 100644
--- a/sgf-tests.el
+++ b/sgf-tests.el
@@ -31,17 +31,6 @@
 (require 'sgf-board)
 (require 'ert)
 
-(ert-deftest sgf-parse-one-large-node-test ()
-  (let* ((str ";GM[1]FF[4]
-               SZ[19]
-               GN[GNU Go 3.7.11 load and print]
-               DT[2008-12-14]
-               KM[0.0]HA[0]RU[Japanese]AP[GNU Go:3.7.11]AW[ja][oa]
-               [pa][db][eb]")
-         (node (car (parse-nodes str))))
-    (should (= (length node) 10))
-    (should (= (length (cdar (last node))) 5))))
-
 (ert-deftest sgf-parse-simple-tree ()
   (let* ((str "(;GM[1]FF[4]
                SZ[19]
@@ -49,9 +38,10 @@
                DT[2008-12-14]
                KM[0.0]HA[0]RU[Japanese]AP[GNU Go:3.7.11]AW[ja][oa]
                [pa][db][eb])")
-         (tree (parse-trees str)))
-    (should (= 1  (length tree)))
-    (should (= 10 (length (first tree))))))
+         (sgf (sgf2el-str str)))
+    (should (= 1  (length sgf)))
+    (should (= 10 (length (first sgf))))
+    (should (= 6  (length (car (last (first sgf))))))))
 
 (ert-deftest sgf-parse-nested-tree ()
   (let* ((str "(;GM[1]FF[4]
@@ -60,11 +50,12 @@
                DT[2008-12-14]
                KM[0.0]HA[0]RU[Japanese]AP[GNU Go:3.7.11]
                (;AW[ja][oa][pa][db][eb] ;AB[fa][ha][ia][qa][cb]))")
-         (tree (parse-trees str)))
-    (should (= 3 (length tree)))
-    (should (= 9 (length (first tree))))
-    (should (= 6 (length (car (second tree)))))
-    (should (= 6 (length (car (third tree)))))))
+         (sgf (sgf2el-str str)))
+    (should (= 2 (length sgf)))
+    (should (= 9 (length (first sgf))))
+    (should (= 2 (length (second sgf))))
+    (should (= 6 (length (car (first (second sgf))))))
+    (should (= 6 (length (car (second (second sgf))))))))
 
 (ert-deftest sgf-parse-file-test ()
   (let ((game (read-from-file "sgf-files/jp-ming-5.sgf")))
diff --git a/sgf2el.el b/sgf2el.el
index 5fa11d2..4c60fa3 100644
--- a/sgf2el.el
+++ b/sgf2el.el
@@ -28,17 +28,22 @@
 ;;; Code:
 (eval-when-compile (require 'cl))
 
-(defvar prop-re "\\([[:alpha:]]+\\)\\(\\(\\[[^\000]*?[^\\]?\\]\\)+\\)")
+(defvar prop-re
+  "\\([[:alpha:]]+\\)\\(\\([[:space:]]*\\[[^\000]*?[^\\]?\\]\\)+\\)")
 
-(defvar prop-val-re "\\[\\([^\000]*?[^\\]?\\)\\]")
+(defvar prop-val-re
+  "\\[\\([^\000]*?[^\\]?\\)\\]")
 
 (defvar sgf2el-special-properties nil
   "A-list of properties and functions to specially convert their values.")
 
-(defun sgf2el (str)
+(defun sgf2el-str (str)
   "Convert a string of sgf into the equivalent Emacs Lisp."
   (with-temp-buffer
-    (insert str) (sgf2el-region (point-min) (point-max)) (buffer-string)))
+    (insert str)
+    (sgf2el-region (point-min) (point-max))
+    (goto-char (point-min))
+    (read (current-buffer))))
 
 (defun make-keyword (string)
   (intern (concat ":" (upcase string))))
@@ -72,19 +77,16 @@
   (interactive "r")
   (let ((start (copy-marker (or start (point-min))))
         (end   (copy-marker (or end   (point-max))))
-        (re    (format "\\(%s\\|%s\\)" prop-re ";"))
+        (re    (format "\\(%s\\|%s\\)" prop-re "\\(([[:space:]]*\\)*\\(;\\)"))
         last-node)
     (save-excursion (goto-char start)
       (while (re-search-forward re end t)
-        (message "1%S 2%S 3%S 4%S 5%S"
-                 (match-string 1)
-                 (match-string 2)
-                 (match-string 3)
-                 (match-string 4)
-                 (match-string 5))
-        (if (string= (match-string 0) ";")
-            (progn (replace-match (if last-node ")(" "("))
-                   (setq last-node t))
+        (if (string= (match-string 6) ";")
+            (progn
+              (replace-match "(" nil nil nil 6)
+              (when last-node
+                (save-excursion (goto-char (match-beginning 0)) (insert ")")))
+              (setq last-node t))
           (let* ((key (sgf2el-convert-prop-key (match-string 2)))
                  (val (sgf2el-convert-prop-vals key
                        (sgf2el-all-matches (match-string 3) prop-val-re 1)))



reply via email to

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