Coder Social home page Coder Social logo

diff-match-patch's People

Contributors

agrostis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

diff-match-patch's Issues

Test diff-timeout fails on slow machines, because for *diff-timeout* affects only part of the code

The test diff-timout fails on slow machines, because the code outside diff-bisect (where it calls past-diff-deadline) is not limited by *diff-timeout*.

This specific test fails for slow machines, but it means similar failures for faster machines on more complex diff operations.

It should either have a way to propagate reaching the deadline out of diff-bisect to the callers, or check in other places too.

Fail to patch by lines.

Hello,

I'm writing a little test to try to understand how to use diff-patch-match.

Everything seems to work nicely for char diffs, but with line patches, I cannot reconstitute the original sequences of lines: the last two assert fail. Why? Is this a bug or did I do something wrong?

(accessorily, it might be nice to have a equal operator to compare hunks before and after writing and reading back).

(ql:quickload :diff-match-patch)

(defparameter *one*  "Hao Wang, logicien americain.

L'algorithme en  question  a  été  publié  en  1960  dans l'IBM Journal,
article intitule \"Toward  Mechanical Mathematics\", avec des variantes et
une  extension au calcul  des  prédicats.  Il  s'agit  ici  du  \"premier
programme\" de Wang, systeme \"P\".

Il observe que les preuves engendrées sont \"essentiellement des arbres\",
et  annonce  que  la  machine  a  démontre 220 théorèmes du  calcul  des
propositions  (tautologies)  en  3  minutes. Il en tire argument pour la
supériorité  d'une  approche  algorithmique  par  rapport à une approche
heuristique comme celle du \"Logic Theorist\" de Newell, Shaw et  Simon (à
partir de 1956 sur la machine JOHNNIAC de la Rand Corporation): un débat
qui dure encore...

Cet  algorithme  a  été popularisé par J. McCarthy, comme exemple­fanion
d'application  de LISP. Il figure dans le manuel de la première  version
de  LISP  (LISP  1,  sur IBM 704 justement, le manuel est daté  de  Mars
1960), et il a été repris dans le celebre \"LISP 1.5 Programmer's Manual\"
publié en 1962 par MIT Press, un des maîtres­livres de l'Informatique.





")

(defparameter *two*  "Hao Wang, logicien americain.

'algorithme en  question  a  été  publié  en  1960  dans l'IBM
Journal, article intitule \"Toward  Mechanical Mathematics\", avec des
variantes et une  extension au calcul  des  prédicats.  Il  s'agit
ici  du  \"premier programme\" de Wang, systeme \"P\".

L'article a été écrit en 1958, et les expériences effectuées sur IBM
704 ­ machine à lampes, 32 k  mots  de 36 bits, celle­là même qui vit
naître LISP à la même époque. Le programme  a  été écrit en assembleur
et  l'auteur estime que \"there is very little in the program that is
not straightforward\".

Il observe que les preuves engendrées sont \"essentiellement des
arbres\", et  annonce  que  la  machine  a  démontre 220 théorèmes du
calcul  des propositions  en  3  minutes. Il en tire
argument pour la supériorité  d'une  approche  algorithmique  par
rapport à une approche heuristique comme celle du \"Logic Theorist\"
de Newell, Shaw et  Simon (à partir de 1956 sur la machine JOHNNIAC de
la Rand Corporation): un débat qui dure encore...

Cet  algorithme  a  été popularisé par J. McCarthy, comme
exemple­fanion d'application  de LISP. Il figure dans le manuel de la
première  version de  LISP, et il a été repris dans le celebre
\"LISP 1.5 Programmer's Manual\" publié en 1962 par MIT Press, un des
maîtres­livres de l'Informatique.  ")

;; char diffs

(defparameter *d* (diff-match-patch:diff *one* *two*))
(assert (string= *one* (diff-match-patch:diff-origin *d*)))
(assert (string= *two* (diff-match-patch:diff-destination *d*)))

(defparameter *p*
  (diff-match-patch:make-patch *one* *two*))

(defparameter *pp*
  (with-input-from-string (inp (with-output-to-string (out)
                                 (diff-match-patch:write-chars-patch *p* out)))
    (diff-match-patch:read-chars-patch inp)))
;; (assert (equalp *p* *pp*)) ;; Why not? ;-)

(multiple-value-bind (new appliedp) (diff-match-patch:apply-patch *p* *one*)
  (assert (every (function identity) appliedp))
  (assert (string= *two* new)))

(multiple-value-bind (new appliedp) (diff-match-patch:apply-patch *pp* *one*)
  (assert (every (function identity) appliedp))
  (assert (string= *two* new)))


;; line diffs

(defparameter *onel* (split-sequence #\newline *one*))
(defparameter *twol* (split-sequence #\newline *two*))

(defparameter *l* (diff-match-patch:diff *onel* *twol* :test (function string=)))
(assert (equal *onel* (diff-match-patch:diff-origin *l*)))
(assert (equal *twol* (diff-match-patch:diff-destination *l*)))

(defparameter *q* (diff-match-patch:make-patch :diffs *l*))
(defparameter *qq*
  (with-input-from-string (inp (with-output-to-string (out)
                                  (diff-match-patch:write-lines-patch *q* out)))
    (diff-match-patch:read-lines-patch inp)))
;; (assert (equalp *q* *qq*)) ;; Why not? ;-)

(multiple-value-bind (new appliedp) (diff-match-patch:apply-patch *q* *onel*)
  (assert (every (function identity) appliedp))
  (assert (equal *twol* new)))

(multiple-value-bind (new appliedp) (diff-match-patch:apply-patch *qq* *onel*)
  (assert (every (function identity) appliedp)) ; FAILS - WHY?
  (assert (equal *twol* new)))                  ; FAILS - WHY?

The function join may apply with too many arguments

The function join does apply #'concatenate on its argument (after removing empty elements), which may end up trying to call concatenate with too many arguments (more than call-arguments-limit).

In the tests, in the diff-timeout test it ends up calling it with 4096 arguments, which at least on LispWorks is bigger than call-arguments-limit (2047). Since the file is compiled with safety 0, it may not give an error, but may crash badly as a result.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.