Browse Source

Refactor breakpoints

* Make breakpoints a CL struct.
* Streamline the communication between the backend and indium-breakpoint.el.
* Add unit tests.
workspaces
Nicolas Petton 3 years ago
parent
commit
dae41c65dc
8 changed files with 255 additions and 219 deletions
  1. +6
    -62
      indium-backend.el
  2. +56
    -65
      indium-breakpoint.el
  3. +7
    -7
      indium-interaction.el
  4. +67
    -0
      indium-structs.el
  5. +17
    -18
      indium-webkit.el
  6. +0
    -56
      test/unit/indium-backend-test.el
  7. +29
    -11
      test/unit/indium-breakpoint-test.el
  8. +73
    -0
      test/unit/indium-structs-test.el

+ 6
- 62
indium-backend.el View File

@ -119,57 +119,19 @@ Evaluate CALLBACK on the filtered candidates.
EXPRESSION should be a valid JavaScript expression string.")
(cl-defgeneric indium-backend-add-breakpoint (backend location &optional callback condition)
"Request the addition of a breakpoint.
The breakpoint is added at LOCATION. When CALLBACK is
non-nil, evaluate it with the breakpoint's id.
(cl-defgeneric indium-backend-add-breakpoint (backend breakpoint &optional callback)
"Request the addition of BREAKPOINT.
Concrete implementations should call
`indium-backend-register-breakpoint' once the addition has been
performed.")
`indium-current-connection-add-breakpoint' once the addition has
been performed.")
(cl-defgeneric indium-backend-remove-breakpoint (backend id)
"Request the removal of the breakpoint with id ID.
Concrete implementations should call
`indium-backend-unregister-breakpoint' once the removal has been
performed.")
(defun indium-backend-remove-all-breakpoints-from-buffer (buffer)
"Remove all breakpoints from BUFFER."
(with-current-buffer buffer
(seq-do (lambda (brk)
(indium-backend-remove-breakpoint (indium-current-connection-backend)
(map-elt brk 'id)))
(indium-backend-get-breakpoints-in-file buffer-file-name))))
(defun indium-backend-register-breakpoint (id line file condition)
"Register the breakpoint with ID at LINE in FILE and CONDITION.
Breakpoints are registered locally in the current connection so
that if a buffer later visits FILE with `indium-interaction-mode'
turned on, the breakpoint can be added back to the buffer."
(let ((breakpoint `((line . ,line)
(file . ,file)
(condition . ,condition))))
(map-put (indium-current-connection-breakpoints) id breakpoint)))
(defun indium-backend-unregister-breakpoint (id)
"Remove the breakpoint with ID from the current connection."
(map-delete (indium-current-connection-breakpoints) id))
(defun indium-backend-get-breakpoints ()
"Return all breakpoints in the current connection.
A breakpoint is an alist with the keys `id', `file', `line' and
`condition'."
(let ((breakpoints (indium-current-connection-breakpoints)))
(map-keys-apply (lambda (key)
`((id . ,key)
(file . ,(map-nested-elt breakpoints `(,key file)))
(line . ,(map-nested-elt breakpoints `(,key line)))
(condition . ,(map-nested-elt breakpoints `(,key condition)))))
breakpoints)))
`indium-current-connection-remove-breakpoint' once the removal
has been performed.")
(cl-defgeneric indium-backend-deactivate-breakpoints (backend)
"Deactivate all breakpoints.
@ -181,24 +143,6 @@ The runtime will not pause on any breakpoint."
The runtime will not pause on any breakpoint."
)
(defun indium-backend-get-breakpoints-in-file (file &optional line)
"Return all breakpoints in FILE at LINE.
If LINE is not provided, return all breakpoints in FILE."
(let ((breakpoints (indium-backend-get-breakpoints)))
(seq-filter (lambda (brk)
(and (string= (map-elt brk 'file) file)
(or (not line)
(= (map-elt brk 'line) line))))
breakpoints)))
(defun indium-backend-get-breakpoint (id)
"Return the breakpoint with ID.
If not found, return nil."
(let ((breakpoints (indium-backend-get-breakpoints)))
(seq-find (lambda (brk)
(eq (map-elt brk 'id) id))
breakpoints)))
(cl-defgeneric indium-backend-set-script-source (backend url source &optional callback)
"Update the contents of the script at URL to SOURCE.")


+ 56
- 65
indium-breakpoint.el View File

@ -30,6 +30,7 @@
(require 'indium-backend)
(require 'indium-faces)
(require 'indium-structs)
(eval-and-compile
(require 'indium-script))
@ -38,67 +39,68 @@
When CONDITION is non-nil, the breakpoint will be hit when
CONDITION is true."
(let ((ov (indium-breakpoint--put-icon condition)))
(let* ((brk (make-indium-breakpoint :file (indium-location-file location)
:line (indium-location-line location)
:condition (or condition ""))))
(indium-breakpoint-add-overlay brk)
(when-indium-connected
(indium-backend-add-breakpoint (indium-current-connection-backend)
location
(lambda (id)
(indium-breakpoint-added id ov))
condition))))
brk))))
(defun indium-breakpoint-edit-condition ()
"Edit condition of breakpoint at point."
(let* ((breakpoint (indium-backend-get-breakpoint (indium-breakpoint-id-at-point)))
(old-condition (map-elt breakpoint 'condition))
(new-condition (read-from-minibuffer
(format "Breakpoint condition (%s): " old-condition)
nil nil nil nil old-condition))
(new-condition (if (string-empty-p new-condition)
old-condition
new-condition)))
(map-put breakpoint 'condition new-condition)
(indium-breakpoint-remove)
(indium-breakpoint-add (indium-script-generated-location-at-point)
new-condition)))
(when-let ((breakpoint (indium-breakpoint-at-point)))
(let* ((old-condition (indium-breakpoint-condition breakpoint))
(new-condition (read-from-minibuffer "Breakpoint condition: "
old-condition nil nil nil old-condition)))
(setf (indium-breakpoint-condition breakpoint) new-condition)
(indium-breakpoint-remove)
(indium-breakpoint-add (indium-script-generated-location-at-point)
new-condition))))
(defun indium-breakpoint-remove ()
"Remove the breakpoint from the current line."
(if-let ((id (indium-breakpoint-id-at-point)))
(if-let ((brk (indium-breakpoint-at-point)))
(when-indium-connected
(indium-backend-remove-breakpoint (indium-current-connection-backend) id)))
(indium-breakpoint--remove-icon))
(indium-backend-remove-breakpoint (indium-current-connection-backend)
(indium-breakpoint-id brk))))
(indium-breakpoint-remove-overlay))
(defun indium-breakpoint-remove-all ()
"Remove all breakpoints from the current buffer's file."
(indium-breakpoint-remove-breakpoints-from-buffer)
(indium-backend-remove-all-breakpoints-from-buffer (current-buffer)))
(indium-breakpoint-remove-all-overlays)
(indium-breakpoint-remove-breakpoints-from-buffer (current-buffer)))
(defun indium-breakpoint-add-breakpoints-to-buffer ()
"Add all breakpoints markers to the current buffer.
This function does not add breakpoints."
(seq-do (lambda (brk)
(save-excursion
(goto-line (1+ (map-elt brk 'line)))
(let ((ov (indium-breakpoint--put-icon)))
(indium-breakpoint-added (map-elt brk 'id) ov))))
(indium-backend-get-breakpoints-in-file buffer-file-name)))
(goto-char (point-min))
(forward-line (indium-location-line (indium-breakpoint-location brk)))
(indium-breakpoint-add-overlay brk)))
(indium-current-connection-get-breakpoints-in-file buffer-file-name)))
(defun indium-breakpoint-remove-breakpoints-from-buffer ()
(defun indium-breakpoint-remove-all-overlays ()
"Remove all breakpoint markers from the current buffer.
This function does no unset breakpoints,"
This function does no unset breakpoints."
(remove-overlays (point-min)
(point-max)
'indium-breakpoint
t))
(defun indium-breakpoint-added (id overlay)
"Add the breakpoint ID to OVERLAY."
(indium-breakpoint--put-id id overlay))
(defun indium-breakpoint-remove-breakpoints-from-buffer (buffer)
"Remove all breakpoints from BUFFER."
(with-current-buffer buffer
(seq-do (lambda (brk)
(indium-backend-remove-breakpoint (indium-current-connection-backend)
(indium-breakpoint-id brk)))
(indium-current-connection-get-breakpoints-in-file buffer-file-name))))
(defun indium-breakpoint-update-breakpoints ()
"Update all breakpoints for the current buffer in the backend."
(when-indium-connected
(indium-backend-remove-all-breakpoints-from-buffer (current-buffer))
(indium-breakpoint-remove-breakpoints-from-buffer (current-buffer))
(indium-breakpoint-restore-breakpoints)))
(defun indium-breakpoint-restore-breakpoints ()
@ -109,41 +111,30 @@ This function is used when reconnecting to a new connection."
(save-excursion
(let ((overlays (overlays-in (point-min) (point-max))))
(seq-doseq (ov overlays)
(when (overlay-get ov 'indium-breakpoint)
(let ((condition (overlay-get ov 'indium-breakpoint-condition))
(start (overlay-start ov)))
(goto-char start)
(indium-breakpoint-add (indium-script-generated-location-at-point)
condition)))))))))
(defun indium-breakpoint--put-icon (&optional condition)
"Add a breakpoint icon on the current line.
The icon is added to the left fringe.
When CONDITION is non-nil, add it to the breakpoint overlay.
Return the overlay."
(let ((ov (indium-breakpoint-ensure-overlay)))
(when-let ((brk (overlay-get ov 'indium-breakpoint))
(start (overlay-start ov)))
(goto-char start)
(indium-breakpoint-add (indium-script-generated-location-at-point)
(indium-breakpoint-condition brk)))))))))
(defun indium-breakpoint-add-overlay (breakpoint)
"Add an overlay for BREAKPOINT on the current line.
An icon is added to the left fringe."
(let ((ov (indium-breakpoint--ensure-overlay)))
(overlay-put ov
'before-string
(indium-breakpoint--fringe-icon))
(when condition
(overlay-put ov
'indium-breakpoint-condition
condition))
(overlay-put ov
'indium-breakpoint
breakpoint)
ov))
(defun indium-breakpoint--put-id (id overlay)
"Put the ID of the breakpoint to OVERLAY."
(overlay-put overlay
'indium-breakpoint-id
id))
(defun indium-breakpoint--remove-icon ()
"Remove the breakpoint icon from the current line."
(defun indium-breakpoint-remove-overlay ()
"Remove the breakpoint overlay from the current line."
(remove-overlays (point-at-bol)
(point-at-eol)
'indium-breakpoint
t))
'indium-breakpoint-ov
t))
(defun indium-breakpoint--fringe-icon ()
"Return the fringe icon used for breakpoints."
@ -157,19 +148,19 @@ If no overlay is present, return nil."
(overlay-get ov 'indium-breakpoint))
(overlays-in (point-at-bol) (point-at-eol))))
(defun indium-breakpoint-ensure-overlay ()
(defun indium-breakpoint--ensure-overlay ()
"Return the breakpoint overlay on the current line.
If there is no overlay, make one."
(or (indium-breakpoint-overlay-on-current-line)
(let ((ov (make-overlay (point-at-bol) (point-at-eol))))
(overlay-put ov 'indium-breakpoint t)
(overlay-put ov 'indium-breakpoint-ov t)
ov)))
(defun indium-breakpoint-id-at-point ()
"Return the id of the breakpoint on the current line.
(defun indium-breakpoint-at-point ()
"Return the breakpoint on the current line.
If there is no breakpoint set on the line, return nil."
(when-let ((ov (indium-breakpoint-overlay-on-current-line)))
(overlay-get ov 'indium-breakpoint-id)))
(overlay-get ov 'indium-breakpoint)))
(defun indium-breakpoint-on-current-line-p ()
"Return non-nil if there is a breakpoint on the current line."


+ 7
- 7
indium-interaction.el View File

@ -169,12 +169,12 @@ hitting a breakpoint."
(defun indium--make-xrefs-from-breakpoints ()
"Return a list of xref objects from all breakpoints."
(seq-map (lambda (breakpoint)
(xref-make (indium--get-breakpoint-xref-match breakpoint)
(xref-make-file-location (map-elt breakpoint 'file)
(1+ (map-elt breakpoint 'line))
0)))
(indium-backend-get-breakpoints)))
(map-values-apply (lambda (breakpoint)
(xref-make (indium--get-breakpoint-xref-match breakpoint)
(xref-make-file-location (map-elt breakpoint 'file)
(1+ (map-elt breakpoint 'line))
0)))
(indium-current-connection-breakpoints)))
(defun indium--get-breakpoint-xref-match (breakpoint)
"Return the source line where BREAKPOINT is set."
@ -274,7 +274,7 @@ hitting a breakpoint."
(defun indium-interaction-mode-off ()
"Function to be evaluated when `indium-interaction-mode' is turned off."
(indium-breakpoint-remove-breakpoints-from-buffer))
(indium-breakpoint-remove-all-overlays))
(defun indium-interaction-update ()
"Update breakpoints and script source of the current buffer."


+ 67
- 0
indium-structs.el View File

@ -34,9 +34,14 @@
;; file, it also contains a `file' slot. Columns and lines start at 0.
;;
;; `indium-frame' represents a call frame in the context of debugging.
;;
;; `indium-breakpoint' represents a breakpoint set at a location with a possible
;; breaking condition.
;;; Code:
(require 'map)
(declare-function indium-script-get-file "indium-script.el")
(declare-function indium-script-find-by-id "indium-script.el")
@ -66,6 +71,21 @@
;; extra properties that can be added by the backend
(props (make-hash-table) :type hash-table))
(defun indium-connection-add-breakpoint (breakpoint connection)
"Add BREAKPOINT to the map of breakpoints in CONNECTION."
(map-put (indium-connection-breakpoints connection)
(indium-breakpoint-id breakpoint)
breakpoint))
(defun indium-connection-remove-breakpoint (id connection)
"Remove the breakpoint with ID from CONNECTION."
(map-delete (indium-connection-breakpoints connection) id))
(defun indium-connection-get-breakpoint (id connection)
"Return the breakpoint with ID in CONNECTION.
If no breakpoint with ID exist in CONNECTION, return nil."
(map-elt (indium-connection-breakpoints connection) id))
(defun indium-current-connection-backend ()
"Return the backend of the current connection if any."
(when-indium-connected
@ -91,6 +111,39 @@
(when-indium-connected
(indium-connection-breakpoints indium-current-connection)))
(defun indium-current-connection-add-breakpoint (breakpoint)
"Add BREAKPOINT to the current connection.
Breakpoints are registered locally in the current connection so
that if a buffer later visits FILE with `indium-interaction-mode'
turned on, the breakpoint can be added back to the buffer."
(when-indium-connected
(indium-connection-add-breakpoint breakpoint indium-current-connection)))
(defun indium-current-connection-remove-breakpoint (id)
"Remove the breakpoint with ID from the current connection."
(when-indium-connected
(indium-connection-remove-breakpoint id indium-current-connection)))
(defun indium-current-connection-get-breakpoint (id)
"Return the breakpoint with ID in the current connection.
If no such breakpoint exist, return nil."
(indium-connection-get-breakpoint id indium-current-connection))
(defun indium-current-connection-get-breakpoints-in-file (file &optional line)
"Return all breakpoints in FILE at LINE.
If LINE is not provided, return all breakpoints in FILE."
(let ((breakpoints (map-values (indium-current-connection-breakpoints))))
(seq-filter (lambda (brk)
(and (string= (indium-location-file
(indium-breakpoint-location brk))
file)
(or (not line)
(= (indium-location-line
(indium-breakpoint-location brk))
line))))
breakpoints)))
(defun indium-current-connection-props ()
"Return the props of the current connection if any."
(when-indium-connected
@ -139,5 +192,19 @@
(type nil :type string :read-only t)
(function-name nil :type string))
(cl-defstruct (indium-breakpoint
(:constructor nil)
(:constructor make-indium-breakpoint
(&key id
line
file
condition
&aux (location (make-indium-location
:line line
:file file)))))
(id nil :type string)
(location nil :type indium-location :read-only t)
(condition "" :type string))
(provide 'indium-structs)
;;; indium-structs.el ends here

+ 17
- 18
indium-webkit.el View File

@ -106,13 +106,11 @@ Evaluate CALLBACK on the filtered candidates."
(lambda (response)
(indium-webkit--handle-completions-response response prefix callback)))))
(cl-defmethod indium-backend-add-breakpoint ((_backend (eql webkit)) location &optional callback condition)
"Request the addition of a breakpoint.
The breakpoint is set at LOCATION. When CALLBACK is
non-nil, evaluate it with the breakpoint's location and id."
(let ((url (indium-workspace-make-url (indium-location-file location)))
(condition (or condition "")))
(cl-defmethod indium-backend-add-breakpoint ((_backend (eql webkit)) breakpoint &optional callback)
"Request the addition of BREAKPOINT."
(let* ((location (indium-breakpoint-location breakpoint))
(file (indium-location-file location))
(url (indium-workspace-make-url file)))
(unless url
(user-error "No URL associated with the current buffer. Setup an Indium workspace first"))
(indium-webkit--send-request
@ -120,18 +118,19 @@ non-nil, evaluate it with the breakpoint's location and id."
(params . ((url . ,url)
(lineNumber . ,(indium-location-line location))
(columnNumber . ,(indium-location-column location))
(condition . ,condition))))
(condition . ,(indium-breakpoint-condition breakpoint)))))
(lambda (response)
(let* ((breakpoint (map-elt response 'result))
(id (map-elt breakpoint 'breakpointId))
(locations (map-elt breakpoint 'locations))
(let* ((result (map-elt response 'result))
(id (map-elt result 'breakpointId))
(locations (map-elt result 'locations))
(line (map-elt (seq--elt-safe locations 0) 'lineNumber)))
(when line
(indium-backend-register-breakpoint id line (indium-location-file location) condition))
(when callback
(unless line
(message "Cannot get breakpoint location"))
(funcall callback id)))))))
(if line
(progn
(setf (indium-breakpoint-id breakpoint) id)
(indium-current-connection-add-breakpoint breakpoint)
(when callback
(funcall callback breakpoint)))
(message "Cannot get breakpoint location")))))))
(cl-defmethod indium-backend-remove-breakpoint ((_backend (eql webkit)) id)
"Request the removal of the breakpoint with id ID."
@ -139,7 +138,7 @@ non-nil, evaluate it with the breakpoint's location and id."
`((method . "Debugger.removeBreakpoint")
(params . ((breakpointId . ,id))))
(lambda (_response)
(indium-backend-unregister-breakpoint id))))
(indium-current-connection-remove-breakpoint id))))
(cl-defmethod indium-backend-deactivate-breakpoints ((_backend (eql webkit)))
"Deactivate all breakpoints.


+ 0
- 56
test/unit/indium-backend-test.el View File

@ -35,61 +35,5 @@
(with-indium-connection (make-indium-connection :backend 'webkit)
(expect (indium-backend-active-connection-p 'webkit) :to-be nil))))
(describe "Backend breakpoints"
(it "can register breakpoints"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond")
(expect (indium-backend-get-breakpoints) :to-equal
'(((id . a)
(file . "foo.js")
(line . 12)
(condition . "cond"))))))
(it "can get breakpoints in a file"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond1")
(indium-backend-register-breakpoint 'b 25 "foo.js" "cond2")
(indium-backend-register-breakpoint 'c 3 "bar.js" "cond3")
(expect (indium-backend-get-breakpoints-in-file "foo.js") :to-equal
'(((id . a)
(file . "foo.js")
(line . 12)
(condition . "cond1"))
((id . b)
(file . "foo.js")
(line . 25)
(condition . "cond2"))))))
(it "can get breakpoints in a file with line"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond1")
(indium-backend-register-breakpoint 'b 25 "foo.js" "cond2")
(indium-backend-register-breakpoint 'c 3 "bar.js" "cond3")
(expect (indium-backend-get-breakpoints-in-file "foo.js" 25) :to-equal
'(((id . b)
(file . "foo.js")
(line . 25)
(condition . "cond2"))))))
(it "can get breakpoint from ID"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond")
(expect (indium-backend-get-breakpoint 'a) :to-equal
'((id . a)
(file . "foo.js")
(line . 12)
(condition . "cond")))))
(it "get nil when no breakpoint found for ID"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond")
(expect (indium-backend-get-breakpoint 'b) :to-equal nil)))
(it "can unregister breakpoints"
(with-indium-connection (make-indium-connection :backend 'fake)
(indium-backend-register-breakpoint 'a 12 "foo.js" "cond")
(indium-backend-unregister-breakpoint 'a)
(expect (indium-backend-get-breakpoints) :to-be nil))))
(provide 'indium-backend-test)
;;; indium-backend-test.el ends here

+ 29
- 11
test/unit/indium-breakpoint-test.el View File

@ -22,7 +22,7 @@
;;; Code:
(require 'buttercup)
(require 'assess)
(require 'indium-breakpoint)
(describe "Accessing breakpoints"
@ -36,28 +36,46 @@
(with-js2-buffer "let a = 1;"
(goto-char (point-min))
(expect (indium-breakpoint-on-current-line-p) :to-be nil)
(indium-breakpoint--put-icon)
(indium-breakpoint-add (make-indium-location))
(expect (indium-breakpoint-on-current-line-p) :to-be-truthy)))
(it "can edit a breakpoint on the current line"
(spy-on #'read-from-minibuffer :and-return-value "new condition")
(spy-on #'indium-breakpoint-remove)
(spy-on #'indium-breakpoint-add)
(spy-on #'indium-breakpoint-remove :and-call-through)
(spy-on #'indium-breakpoint-add :and-call-through)
(with-js2-buffer "let a = 1;"
(goto-char (point-min))
(indium-breakpoint-add 'position "old condition")
(indium-breakpoint-edit-condition)
(expect #'read-from-minibuffer :to-have-been-called)
(expect #'indium-breakpoint-remove :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with (make-indium-location) "new condition"))))
(let ((location (make-indium-location :file buffer-file-name
:line 0)))
(indium-breakpoint-add location "old condition")
(indium-breakpoint-edit-condition)
(expect #'read-from-minibuffer :to-have-been-called)
(expect #'indium-breakpoint-remove :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with location "new condition")))))
(describe "Breakpoint duplication handling"
(it "can add a breakpoint multiple times on the same line without duplicating it"
(with-temp-buffer
(indium-breakpoint--put-icon)
(indium-breakpoint-add (make-indium-location))
(let ((number-of-overlays (seq-length (overlays-in (point-min) (point-max)))))
(indium-breakpoint--put-icon)
(indium-breakpoint-add (make-indium-location))
(expect (seq-length (overlays-in (point-min) (point-max))) :to-equal number-of-overlays)))))
(describe "Restoring breakpoints"
(it "can restore breakpoints from buffers when opening a new connection"
(spy-on 'indium-backend-add-breakpoint)
(spy-on 'indium-breakpoint-add :and-call-through)
(with-js2-buffer "let a = 2;"
(goto-char (point-min))
(let ((loc (make-indium-location))
(condition "condition"))
(indium-breakpoint-add loc condition)
;; simulate getting the breakpoint ID from a backend
(setf (indium-breakpoint-id (indium-breakpoint-at-point)) 'id)
(with-fake-indium-connection
(indium-breakpoint-restore-breakpoints)
(expect #'indium-backend-add-breakpoint :to-have-been-called)
(expect #'indium-breakpoint-add :to-have-been-called-with loc condition))))))
(provide 'indium-breakpoint-test)
;;; indium-breakpoint-test.el ends here

+ 73
- 0
test/unit/indium-structs-test.el View File

@ -40,5 +40,78 @@
(expect (indium-current-connection-current-frame)
:to-be 'foo))))
(describe "Struct creation"
(it "should be able to make locations from script ids"
(spy-on 'indium-script-get-file :and-return-value "foo.js")
(spy-on 'indium-script-find-by-id :and-return-value "id")
(let ((loc (make-indium-location-from-script-id
:script-id "id"
:line 2
:column 3)))
(expect #'indium-script-find-by-id :to-have-been-called-with "id")
(expect (indium-location-file loc) :to-equal "foo.js")))
(it "Should be able to make breakpoints"
(let ((brk (make-indium-breakpoint
:id 'id
:line 5
:file "foo.js")))
(expect (indium-breakpoint-id brk) :to-be 'id)
(expect (indium-location-file (indium-breakpoint-location brk))
:to-equal "foo.js")
(expect (indium-location-line (indium-breakpoint-location brk))
:to-equal 5)
(expect (indium-location-column (indium-breakpoint-location brk))
:to-equal 0))))
(describe "Manipulating breakpoints"
(it "can register breakpoints"
(with-indium-connection (make-indium-connection)
(expect (indium-current-connection-get-breakpoint 'a) :to-be nil)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'a) :to-be brk))))
(it "can get breakpoints in a file"
(with-indium-connection (make-indium-connection)
(let ((brks (seq-map (lambda (data)
(apply #'make-indium-breakpoint data))
'((:id a :line 12 :file "foo.js" :condition "cond1")
(:id b :line 25 :file "foo.js" :condition "cond2")
(:id c :line 3 :file "bar.js" :condition "cond3")))))
(seq-do #'indium-current-connection-add-breakpoint brks)
(expect (indium-current-connection-get-breakpoints-in-file "foo.js") :to-equal
(list (car brks) (cadr brks))))))
(it "can get breakpoints in a file with line"
(with-indium-connection (make-indium-connection)
(let ((brks (seq-map (lambda (data)
(apply #'make-indium-breakpoint data))
'((:id a :line 12 :file "foo.js" :condition "cond1")
(:id b :line 25 :file "foo.js" :condition "cond2")
(:id c :line 3 :file "bar.js" :condition "cond3")))))
(seq-do #'indium-current-connection-add-breakpoint brks)
(expect (indium-current-connection-get-breakpoints-in-file "foo.js" 25) :to-equal
(list (cadr brks))))))
(it "can get breakpoint from ID"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'a) :to-be brk))))
(it "gets nil when no breakpoint found for ID"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(expect (indium-current-connection-get-breakpoint 'b) :to-equal nil))))
(it "can unregister breakpoints"
(with-indium-connection (make-indium-connection)
(let ((brk (make-indium-breakpoint :id 'a :line 12 :file "foo.js" :condition "cond")))
(indium-current-connection-add-breakpoint brk)
(indium-current-connection-remove-breakpoint 'a)
(expect (map-values (indium-current-connection-breakpoints)) :to-be nil)))))
(provide 'indium-structs-test)
;;; indium-structs-test.el ends here

Loading…
Cancel
Save