aboutsummaryrefslogtreecommitdiff
path: root/test/unitsToRanges.js
diff options
context:
space:
mode:
authorAndrew Harvey <andrew@alantgeo.com.au>2021-05-05 20:32:42 +1000
committerAndrew Harvey <andrew@alantgeo.com.au>2021-05-05 20:32:42 +1000
commita219a8abad1110b3dcf9b7d95291b9a42f6f8880 (patch)
tree9f606f578e4a3adeef866d167ab9d25e7d34cecc /test/unitsToRanges.js
parent71c5ec5950d9cf30cc1200ac0c22432dfd7ac1eb (diff)
lib unitsToRanges
Diffstat (limited to 'test/unitsToRanges.js')
-rw-r--r--test/unitsToRanges.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unitsToRanges.js b/test/unitsToRanges.js
new file mode 100644
index 0000000..53d08aa
--- /dev/null
+++ b/test/unitsToRanges.js
@@ -0,0 +1,43 @@
+const test = require('tape')
+
+const unitsToRanges = require('../lib/unitsToRanges.js')
+
+test('units list to addr:flats', t => {
+ t.same(
+ unitsToRanges([]),
+ null,
+ 'empty input returns empty output'
+ )
+
+ t.same(
+ unitsToRanges(['1'], 100),
+ '1',
+ 'single unit'
+ )
+
+ t.same(
+ unitsToRanges(['1', '3']),
+ '1;3',
+ 'two units without a range'
+ )
+
+ t.same(
+ unitsToRanges(['1', '2']),
+ '1-2',
+ 'two consecutive units form a range'
+ )
+
+ t.same(
+ unitsToRanges(['1', '2', '3']),
+ '1-3',
+ 'three consecutive units form a range'
+ )
+
+ t.same(
+ unitsToRanges(['1', '2', '4']),
+ '1-2;4',
+ 'range and singular'
+ )
+
+ t.end()
+})