splittable: klare Fehler für -0 und mehr als 676 Stücke
This commit is contained in:
@@ -17,6 +17,7 @@ folgen [Semantic Versioning](https://semver.org/lang/de/). Die Version steht in
|
|||||||
- README und `man/row.man` erklären, warum `select` in bash/zsh/ksh einen Syntaxfehler gibt und wie man es trotzdem aufruft.
|
- README und `man/row.man` erklären, warum `select` in bash/zsh/ksh einen Syntaxfehler gibt und wie man es trotzdem aufruft.
|
||||||
|
|
||||||
### Behoben
|
### Behoben
|
||||||
|
- `splittable -0` und mehr als 676 Stücke endeten mit einem Ruby-Abbruch (im zweiten Fall nach 676 geschriebenen Dateien). Jetzt eine Fehlermeldung, und es wird vorher geprüft, damit nichts halb geschrieben wird.
|
||||||
- `rdb man` zeigte `\\select` in den Man-Pages als `\elect`: ein doppelter Backslash wird jetzt zuerst geschützt.
|
- `rdb man` zeigte `\\select` in den Man-Pages als `\elect`: ein doppelter Backslash wird jetzt zuerst geschützt.
|
||||||
|
|
||||||
## [0.5.0] - 2026-10-11
|
## [0.5.0] - 2026-10-11
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Colors
|
||||||
|
------
|
||||||
|
black
|
||||||
|
blue
|
||||||
|
carmel
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Colors
|
||||||
|
------
|
||||||
|
green
|
||||||
|
purple
|
||||||
|
red
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Colors
|
||||||
|
------
|
||||||
|
silver
|
||||||
|
white
|
||||||
@@ -164,12 +164,14 @@ end
|
|||||||
Rdb.register('splittable', 'Divide a table horizontally', 'splittable [-n] table') do |args|
|
Rdb.register('splittable', 'Divide a table horizontally', 'splittable [-n] table') do |args|
|
||||||
n = 50
|
n = 50
|
||||||
n = args.shift[1..].to_i if args.first&.match?(/\A-\d+\z/)
|
n = args.shift[1..].to_i if args.first&.match?(/\A-\d+\z/)
|
||||||
die 'usage: splittable [-n] table' unless args.size == 1
|
die 'usage: splittable [-n] table (n is at least 1)' unless args.size == 1 && n.positive?
|
||||||
|
|
||||||
t = open_table(args[0])
|
t = open_table(args[0])
|
||||||
|
chunks = t.rows.each_slice(n).to_a
|
||||||
|
die "#{args[0]}: #{t.rows.size} rows in pieces of #{n} need #{chunks.size} files, but there are only 676 names (aa to zz)" if chunks.size > 676
|
||||||
|
|
||||||
suffix = ('aa'..'zz').each
|
suffix = ('aa'..'zz').each
|
||||||
t.rows.each_slice(n) do |chunk|
|
chunks.each { |chunk| File.write("#{args[0]}#{suffix.next}", t.with(rows: chunk).to_s) }
|
||||||
File.write("#{args[0]}#{suffix.next}", t.with(rows: chunk).to_s)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# ---- aggregates ------------------------------------------------------------
|
# ---- aggregates ------------------------------------------------------------
|
||||||
|
|||||||
@@ -5,6 +5,21 @@ require 'pty'
|
|||||||
require_relative '../lib/rdb'
|
require_relative '../lib/rdb'
|
||||||
|
|
||||||
class SelectionTest < RdbCase
|
class SelectionTest < RdbCase
|
||||||
|
def test_splittable_pieces_and_errors
|
||||||
|
out, = run3('splittable', '-4', 'inventory')
|
||||||
|
assert_equal 4, data(File.read(File.join(@dir, 'inventoryaa'))).size
|
||||||
|
assert_equal 3, data(File.read(File.join(@dir, 'inventoryab'))).size
|
||||||
|
assert_includes File.read(File.join(@dir, 'inventoryab')), "Item\tAmount"
|
||||||
|
_o, err, st = run3('splittable', '-0', 'inventory')
|
||||||
|
refute st.success?
|
||||||
|
assert_match(/usage/, err)
|
||||||
|
write('big', "N\n-\n#{(1..700).to_a.join("\n")}\n")
|
||||||
|
_o, err, st = run3('splittable', '-1', 'big')
|
||||||
|
refute st.success?
|
||||||
|
assert_match(/only 676 names/, err)
|
||||||
|
assert_empty Dir[File.join(@dir, 'bigaa')] # nothing is written when it cannot all be written
|
||||||
|
end
|
||||||
|
|
||||||
def test_record_zero_and_one_are_the_first_and_negatives_count_from_the_end
|
def test_record_zero_and_one_are_the_first_and_negatives_count_from_the_end
|
||||||
{ '0' => '1', '1' => '1', '2' => '3', '3' => '6', '-1' => '6', '-2' => '3', '-3' => '1', '+2' => '3' }.each do |n, item|
|
{ '0' => '1', '1' => '1', '2' => '3', '3' => '6', '-1' => '6', '-2' => '3', '-3' => '1', '+2' => '3' }.each do |n, item|
|
||||||
assert_equal [[item]], data(rdb('record', n, file: 'owners')).map { |r| r.first(1) }, "record #{n}"
|
assert_equal [[item]], data(rdb('record', n, file: 'owners')).map { |r| r.first(1) }, "record #{n}"
|
||||||
|
|||||||
Reference in New Issue
Block a user