~technomancy/fennel

fix #45 v1 APPLIED

Andrey Orst: 1
 fix #45

 3 files changed, 12 insertions(+), 24 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~technomancy/fennel/patches/19797/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] fix #45 Export this patch

Added check that integer keys are successfully incremented by 1
---
 fennelview.lua      | 25 +++++--------------------
 src/fennel/view.fnl |  5 ++++-
 test/core.fnl       |  6 +++---
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/fennelview.lua b/fennelview.lua
index 63a9773..586da79 100644
--- a/fennelview.lua
+++ b/fennelview.lua
@@ -24,12 +24,14 @@ local function sort_keys(_0_0, _1_0)
end
local function table_kv_pairs(t)
  local assoc_3f = false
  local i = 1
  local kv = {}
  local insert = table.insert
  for k, v in pairs(t) do
    if (type(k) ~= "number") then
    if ((type(k) ~= "number") or (k ~= i)) then
      assoc_3f = true
    end
    i = (i + 1)
    insert(kv, {k, v})
  end
  table.sort(kv, sort_keys)
@@ -313,25 +315,8 @@ local function pp_table(x, options, indent)
  return x0
end
local function number__3estring(n)
  local _2_0, _3_0, _4_0 = math.modf(n)
  if ((nil ~= _2_0) and (_3_0 == 0)) then
    local int = _2_0
    return tostring(int)
  else
    local _5_
    do
      local frac = _3_0
      _5_ = (((_2_0 == 0) and (nil ~= _3_0)) and (frac < 0))
    end
    if _5_ then
      local frac = _3_0
      return ("-0." .. tostring(frac):gsub("^-?0.", ""))
    elseif ((nil ~= _2_0) and (nil ~= _3_0)) then
      local int = _2_0
      local frac = _3_0
      return (int .. "." .. tostring(frac):gsub("^-?0.", ""))
    end
  end
  local _2_0 = string.gsub(tostring(n), ",", ".")
  return _2_0
end
local function colon_string_3f(s)
  return s:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")
diff --git a/src/fennel/view.fnl b/src/fennel/view.fnl
index 8938e23..63f9df5 100644
--- a/src/fennel/view.fnl
+++ b/src/fennel/view.fnl
@@ -24,11 +24,14 @@
  ;; [:a :b :c] => [[1 :a] [2 :b] [3 :c]]
  ;; {:a 1 :b 2} => [[:a 1] [:b 2]]
  (var assoc? false)
  (var i 1)
  (let [kv []
        insert table.insert]
    (each [k v (pairs t)]
      (when (not= (type k) :number)
      (when (or (not= (type k) :number)
                (not= k i))
        (set assoc? true))
      (set i (+ i 1))
      (insert kv [k v]))
    (table.sort kv sort-keys)
    (if (= (length kv) 0)
diff --git a/test/core.fnl b/test/core.fnl
index 8deba43..daecd0d 100644
--- a/test/core.fnl
+++ b/test/core.fnl
@@ -352,7 +352,7 @@
               "((require :fennel.view) [1 2 [3 4]] {:sequential-length 2})"
               "[1\n 2\n [3 4]]"
               "((require :fennel.view) {[1] [2 [3]] :data {4 {:data 5} 6 [0 1 2 3]}} {:sequential-length 3})"
               "{:data [{:data 5}\n        [0\n         1\n         2\n         3]]\n [1] [2 [3]]}"
               "{:data {4 {:data 5}\n        6 [0\n           1\n           2\n           3]}\n [1] [2 [3]]}"
               "((require :fennel.view) {{:a 1} {:b 2 :c 3}})"
               "{{:a 1} {:b 2 :c 3}}"
               "((require :fennel.view) [{:aaa [1 2 3]}] {:sequential-length 2})"
@@ -368,8 +368,8 @@
               "\"ваыв\""
               "((require :fennel.view) {[1] [2 [3]] :ваыв {4 {:ваыв 5} 6 [0 1 2 3]}} {:sequential-length 3})"
               (if _G.utf8
                   "{\"ваыв\" [{\"ваыв\" 5}\n         [0\n          1\n          2\n          3]]\n [1] [2 [3]]}"
                   "{\"ваыв\" [{\"ваыв\" 5}\n             [0\n              1\n              2\n              3]]\n [1] [2 [3]]}")
                   "{\"ваыв\" {4 {\"ваыв\" 5}\n         6 [0\n            1\n            2\n            3]}\n [1] [2 [3]]}"
                   "{\"ваыв\" {4 {\"ваыв\" 5}\n             6 [0\n                1\n                2\n                3]}\n [1] [2 [3]]}")
               ;; the next one may look incorrect in some editors, but is actually correct
               "((require :fennel.view) {:ǍǍǍ {} :ƁƁƁ {:ǍǍǍ {} :ƁƁƁ {}}} {:associative-length 1})"
               (if _G.utf8 ; older versions of Lua can't indent this correctly
-- 
2.29.2
Andrey Orst <andreyorst@gmail.com> writes: