(ns javascript-externs-generator.extern-test
  (:require [cljs.test :refer-macros [deftest is testing run-tests]]
            [javascript-externs-generator.extern :as extern]))

(enable-console-print!)

(deftest function
  (let [js-object (clj->js {"testFunction" #()})]
    (is (= "var TEST = {\"testFunction\": function () {}};"
           (extern/extract "TEST" js-object)))))

(deftest property
  (let [js-object (clj->js {"testProperty" "value"})]
    (is (= "var TEST = {\"testProperty\": {}};"
           (extern/extract "TEST" js-object)))))

(deftest object
  (let [js-object (clj->js {"testObject" {"testProperty" "value"}})]
    (is (= "var TEST = {\"testObject\": {\"testProperty\": {}}};"
           (extern/extract "TEST" js-object)))))

(deftest prototype
  (let [js-object (clj->js {"testFunction" #()})]
    (set! (.. js-object -testFunction -prototype -testPrototypeFunction) #())
    (is (= "var TEST = {\"testFunction\": function () {}};TEST.testFunction.prototype = {\"testPrototypeFunction\": function () {}};"
           (extern/extract "TEST" js-object)))))

(ns javascript-externs-generator.extern-test
  (:require [cljs.test :refer-macros [deftest is testing run-tests]]
            [javascript-externs-generator.extern :as extern]))

(enable-console-print!)

(defn compare! [expected, js-string]
  (js/eval js-string)
  (is (= expected (extern/extract "TEST" js/TEST))))

(deftest function
  (let [js-string "function TEST() {}"
        expected "var TEST = {\"testFunction\": function () {}};"]
    (compare! expected js-string)))

(deftest property
  (let [js-string "var TEST = {testProperty: \"value\"}"
        expected "var TEST = {\"testProperty\": {}};"]
    (compare! expected js-string)))

(deftest object
  (let [js-string "var TEST = {testObject: {testProperty: \"value\"}}"
        expected "var TEST = {\"testObject\": {\"testProperty\": {}}};"]
    (compare! expected js-string)))

(deftest prototype
  (let [js-string "var TEST = {testFunction: function(){}}; TEST.testFunction.prototype = {testPrototypeFunction: function() {}}"
        expected "var TEST = {\"testFunction\": function () {}};TEST.testFunction.prototype = {\"testPrototypeFunction\": function () {}};"]
    (compare! expected js-string)))

Change test format - input is defined as a JS string that gets eval'd.
Change test format - input is defined as a JS string that gets eval'd.

jmmk/javascript-externs-generator,jmmk/javascript-externs-generator