Browse Source

Separate handling object values from previews in Webkit

workspaces
Nicolas Petton 4 years ago
parent
commit
b312ef504b
3 changed files with 43 additions and 26 deletions
  1. +1
    -1
      indium-render.el
  2. +15
    -15
      indium-webkit.el
  3. +27
    -10
      test/unit/indium-webkit-test.el

+ 1
- 1
indium-render.el View File

@ -135,7 +135,7 @@ definitions."
mouse-face highlight
indium-reference ,value))
(when preview
(insert preview))))
(insert (format " %s" preview)))))
(defun indium-render-properties (properties)
"Insert all items in PROPERTIES sorted by name."


+ 15
- 15
indium-webkit.el View File

@ -540,18 +540,9 @@ RESULT should be a reference to a remote object."
(pcase type
(`undefined "undefined")
(`function "function")
(`number (if (numberp value)
(number-to-string value)
value))
(`number (number-to-string value))
(`string (format "\"%s\"" value))
;; The server can either send:
;;
;; { type: "boolean", value: "true" }
;; { type: "boolean", value: true }
;;
;; See https://bugs.chromium.org/p/chromium/issues/detail?id=724092
(`boolean (if (or (equal value "true")
(eq value t))
(`boolean (if (eq value t)
"true"
"false"))
(_ (or value "null"))))))
@ -567,11 +558,11 @@ RESULT should be a reference to a remote object."
(defun indium-webkit--preview-object (preview)
"Return a preview string from the properties of the object PREVIEW."
(concat " { "
(concat "{ "
(mapconcat (lambda (prop)
(format "%s: %s"
(map-elt prop 'name)
(indium-webkit--description prop)))
(indium-webkit--preview-property prop)))
(map-elt preview 'properties)
", ")
(if (eq (map-elt preview 'lossless) :json-false)
@ -580,15 +571,24 @@ RESULT should be a reference to a remote object."
(defun indium-webkit--preview-array (preview)
"Return a preview string from the elements of the array PREVIEW."
(concat " [ "
(concat "[ "
(mapconcat (lambda (prop)
(format "%s" (indium-webkit--description prop)))
(indium-webkit--preview-property prop))
(map-elt preview 'properties)
", ")
(if (eq (map-elt preview 'lossless) :json-false)
"… ]"
" ]")))
(defun indium-webkit--preview-property (property)
"Return the string for a single object or array PROPERTY preview."
(if (equal (map-elt property 'type) "string")
(format "\"%s\"" (map-elt property 'value))
(let ((preview (map-elt property 'value)))
(if (seq-empty-p preview)
(map-elt property 'type)
preview))))
(defun indium-webkit--properties (result)
"Return a list of object properties built from RESULT."
(seq-map (lambda (prop)


+ 27
- 10
test/unit/indium-webkit-test.el View File

@ -121,19 +121,36 @@
(describe "Webkit backend result description string"
;; The server can send boolean description values either as a string or boolean.
;; See https://bugs.chromium.org/p/chromium/issues/detail?id=724092
(it "can render boolean descriptions formatted as string values (GitHub issue #52)"
(expect (indium-webkit--description '((type . "boolean") (value . "true")))
:to-equal "true")
(expect (indium-webkit--description '((type . "boolean") (value . "false")))
:to-equal "false"))
(it "can render boolean descriptions"
(expect (indium-webkit--description '((type . "boolean") (value . t)))
:to-equal "true")
:to-equal "true")
(expect (indium-webkit--description '((type . "boolean") (value . :json-false)))
:to-equal "false")))
:to-equal "false")))
(describe "Webkit backend object preview"
(it "can render array previews with booleans (GitHub issue #52)"
(expect (indium-webkit--preview '((type . "object")
(subtype . "array")
(className . "Array")
(description . "Array[1]")
(objectId . "{\"injectedScriptId\":12,\"id\":38}")
(preview (type . "object")
(subtype . "array")
(description . "Array[1]")
(overflow . :json-false)
(properties . [((name . "0") (type . "boolean") (value . "true"))]))))
:to-equal "[ true ]"))
(it "can render object previews with booleans (GitHub issue #52)"
(expect (indium-webkit--preview '((type . "object")
(className . "Object")
(description . "Object")
(objectId . "{\"injectedScriptId\":12,\"id\":43}")
(preview (type . "object")
(description . "Object")
(overflow . :json-false)
(properties . [((name . "a") (type . "boolean") (value . "true"))]))))
:to-equal "{ a: true }")))
(provide 'indium-webkit-test)
;;; indium-webkit-test.el ends here

Loading…
Cancel
Save