Initial package

epel9 imports/epel9/rubygem-scanf-1.0.0-1.el9
Ewoud Kohl van Wijngaarden 2 years ago
parent ea1593e8ba
commit f5e45c0140
No known key found for this signature in database
GPG Key ID: C6EC8F04A934BAB1

3
.gitignore vendored

@ -0,0 +1,3 @@
/*.rpm
/results_rubygem-scanf/
/scanf-*.gem

@ -0,0 +1,22 @@
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

@ -0,0 +1,6 @@
this is 33 a fun
little input file
with
characters

@ -0,0 +1,70 @@
%global gem_name scanf
Name: rubygem-%{gem_name}
Version: 1.0.0
Release: %autorelease
Summary: A Ruby implementation of the C function scanf(3)
License: BSD
URL: https://github.com/ruby/scanf
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
# License is not included in the gem, copied from git
Source1: LICENSE.txt
# Tests are not included in the gem, copied from git
Source2: data.txt
Source3: test_scanf.rb
Source4: test_scanfblocks.rb
Source5: test_scanfio.rb
BuildRequires: ruby(release)
BuildRequires: rubygems-devel
BuildRequires: ruby >= 2.3.0
# Required for %check
BuildRequires: rubygem(test-unit)
BuildArch: noarch
%description
A Ruby implementation of the C function scanf(3).
%package doc
Summary: Documentation for %{name}
Requires: %{name} = %{version}-%{release}
BuildArch: noarch
%description doc
Documentation for %{name}.
%prep
%setup -q -n %{gem_name}-%{version}
cp %{SOURCE1} LICENSE.txt
%build
# Create the gem as gem install only works on a gem file
gem build ../%{gem_name}-%{version}.gemspec
# %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir
# by default, so that we can move it into the buildroot in %%install
%gem_install
%install
mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* \
%{buildroot}%{gem_dir}/
%check
ruby -I.%{gem_instdir}/lib %{SOURCE3} %{SOURCE4} %{SOURCE5}
%files
%license LICENSE.txt
%dir %{gem_instdir}
%{gem_libdir}
%exclude %{gem_cache}
%{gem_spec}
%files doc
%doc %{gem_docdir}
%changelog
%autochangelog

@ -0,0 +1 @@
SHA512 (scanf-1.0.0.gem) = bf502c227174fdfe26202cdda8b404642adba6fbc4524a14d9ad3873a10a5d60a948b477bba8dec95bc34f8f7d446a96abf7b736d7d9adcf8cdf67aa13a0c635

@ -0,0 +1,305 @@
# frozen_string_literal: false
# $Id$
#
# scanf for Ruby
#
# Unit tests
#
require 'scanf.rb'
require 'test/unit'
require 'tempfile'
# Comment out either of these lines to skip those tests.
class TestStringScanf < Test::Unit::TestCase;end
class TestIOScanf < Test::Unit::TestCase;end
module ScanfTests
def tests
[
# Scratchpad
[ "%2[a]", "nbc", []],
[ "%*d %*3d %*s", "123 +456 abc", [] ],
[ "%d%c", "123 x", [ 123, " " ] ],
[ "%d%c", "123x", [ 123, "x" ] ],
[ "%d %c", "123x", [ 123, "x" ] ],
[ "%d %c", "123 x", [ 123, "x" ] ],
# Testing failures
[ "%x", "x", [] ],
[ "%2x", "x", [] ],
[ "%i", "x", [] ],
# ]; end; def nothing; [
[ "%2i", "x", [] ],
[ "%2o", "x", [] ],
[ "%d", "x", [] ],
[ "%2d", "x", [] ],
[ "%3d", "+x3", [] ],
[ "%d%[abc]", "eabc", [] ],
[ "%d\n%[abc]", "\neabc", [] ],
[ "%d%[^abc]", "ghiabc", [ ] ],
[ "%d%[abc]", "abc", [] ],
[ "%d%s", "", [] ],
[ "%d%s", "blah 123 string", [] ],
[ "%[\n]", "abc\n", [] ],
[ "%f", "x", [] ],
[ "%f", "z", [] ],
[ "%f", "z3.2534", [] ],
[ "", "", [] ],
[ "", "abc 123", [] ],
[ '%[^\\w]%c', "a...1", [] ],
# Testing 'x'
[ "%3x", "0xz", [0] ],
# Testing 'i'
[ "%3i", "097", [0] ],
[ "%3i", "0xz", [0] ],
[ "%1i", "3", [ 3 ] ],
[ "%2i", "07", [ 7 ] ],
[ "%2i", "0a", [ 0 ] ],
# Testing 'c'
[ "%3c", "abc", [ "abc" ] ],
[ "%3c", "a\nb", [ "a\nb" ] ],
[ "%3c", "a\nbcd", [ "a\nb" ] ],
[ "%c\n\n", "x\n\n", [ "x" ] ],
[ "%c", "\n", [ "\n" ] ],
[ "%c", "x\n", [ "x" ] ],
[ "%2c", " 123", [" 1"] ],
[ " %c", " x", ["x"] ],
[ "%c", " x", [" "] ],
[ "%c", "123", ["1"] ],
[ "%2c", "123", ["12"] ],
[ "%5c", "a\nb\n\n", [ "a\nb\n\n" ] ],
[ "%6c", "a\nb\n\nx", [ "a\nb\n\nx" ] ],
[ "%5c", "ab\ncd", [ "ab\ncd" ] ],
# Testing 'o'
[ "%3o", "0xz", [0] ],
# Testing 'd'
[ "%d", "\n123", [ 123 ] ],
[ "%d", "\n\n123", [ 123 ] ],
[ "%1d", "2", [2] ],
# Mixed tests
# Includes:
# whitespace/newline
# mixed integer bases
# various mixed specifiers
[ "%[^\\w]%c", "...1", [ "...", "1"] ],
[ "%[abc\n]%d", "a\n\nb\n\nc 123", [ "a\n\nb\n\nc", 123 ] ],
[ "%[abc\n]%d", "a\n\nb\n\nc \t 123", [ "a\n\nb\n\nc", 123 ] ],
[ "%[abc\t]%d", "a\t\tb\t\tc 123", [ "a\t\tb\t\tc", 123 ] ],
[ "%d%3[abc\n]", "123a\nbeaab", [ 123, "a\nb" ] ],
[ "%d%20c", "42 is the key", [ 42, " is the key" ] ],
[ "%d %20c", "42 is the key", [ 42, "is the key" ] ],
[ "%d%3[^abc\n]%d", "123de\nf123", [ 123, "de" ] ],
[ "%d %4c", "3abc", [ 3, "abc" ] ],
[ "%f%d\n%[abc]", "1\neabc", [1.0] ],
[ "%d%3[abc]", "123aaab", [ 123, "aaa" ] ],
[ "%d%3[abc]", "123 aaab", [ 123 ] ],
[ "%d%3[abc]", "123aeaab", [ 123, "a" ] ],
[ "%d%[^abc]", "123defabc", [123, "def" ] ],
[ "%d%3[^abc]", "123defdef", [ 123, "def" ] ],
[ "%d%3[^abc] ", "123defdef ", [ 123, "def" ] ],
[ "%d%3[^abc]ghi", "123defghi", [ 123, "def" ] ],
[ "%d%3[^abc]", "123adefdef", [ 123 ] ],
[ "%d%3[^abc]", "123deafdef", [ 123, "de" ] ],
[ "%d%3[^abc\n]", "123de\nf", [ 123, "de" ] ],
[ "%s%c%c%s", "abc\n\ndef", ["abc", "\n","\n", "def" ] ],
[ "%c%d", "\n\n123", [ "\n",123 ] ],
[ "%s%c%d", "abc\n123", [ "abc", "\n", 123 ] ],
[ "%s%c%d", "abc\n\n123", [ "abc", "\n", 123 ] ],
[ "%c%d", "\t\n123", [ "\t",123 ] ],
[ "%s%c%d", "abc\t\n123", [ "abc", "\t", 123 ] ],
[ "%3c%d", "abc123", [ "abc", 123 ] ],
[ "%3c\n%d", "abc123", [ "abc", 123 ] ],
[ "%3c\n%d", "abc 123", [ "abc", 123 ] ],
[ "%3c %d", "abc123", [ "abc", 123 ] ],
[ "%3c\t%d", "abc \n 123", [ "abc", 123 ] ],
[ "%3c\t%d", "abc \n 123 ", [ "abc", 123 ] ],
[ "%3c%d", "a\nb123", [ "a\nb", 123 ] ],
[ "%f%3c", "1.2x\ny", [ 1.2, "x\ny"] ],
[ "%d\n%d\n%d", "123 456 789", [ 123,456,789 ] ],
[ "%d\n%i%2d%x\n%d", "123 0718932", [ 123, 071, 89, 0x32] ],
[ "%c\n%c", "x y", [ "x", "y" ] ],
[ "%c\t%c", "x y", [ "x", "y" ] ],
[ "%s\n%s", "x y", [ "x", "y" ] ],
[ "%s%s\n", "x y", [ "x", "y" ] ],
[ "%c\n\n%c", "x\n\ny", [ "x", "y" ] ],
[ "%s%d%d", "abc\n123\n456", [ "abc", 123, 456 ] ],
[ "%3s%c%3c%d", "1.2x\n\ny123", [ "1.2", "x", "\n\ny", 123 ] ],
[ "%c\n%c", "x\n\ny", [ "x", "y" ] ],
[ "%c %c", "x\n\ny", [ "x", "y" ] ],
[ "%s\n\n%c", "x\n\ny", [ "x", "y" ] ],
[ "%s\n\n%s", "x\n\ny", [ "x", "y" ] ],
[ "%d\n\n%d", "23\n\n45", [ 23, 45 ] ],
[ "%d\n%d", "23\n\n45", [ 23, 45 ] ],
[ "%c\n\n%c", "x y", [ "x", "y" ] ],
[ "%c%c", "x\n\ny", [ "x", "\n" ] ],
[ "%c%c", "x\n", [ "x", "\n" ] ],
[ "%d%c%c%d", "345 678", [ 345, " ", " ", 678] ],
[ "%d %c%s", "123 x hello", [123, "x", "hello"] ],
[ "%d%2c", "654 123", [654," 1"] ],
[ "%5c%s", "a\nb\n\nxyz", [ "a\nb\n\n","xyz" ] ],
[ "%s%[ xyz]%d", "hello x 32", ["hello", " x ", 32] ],
[ "%5s%8[a-z]%d", "helloblahblah 32", ["hello", "blahblah", 32] ],
[ '%s%[abcde\\s]%d', "hello badea 32", ["hello", " badea ", 32] ],
[ '%d%[\\s]%c', "123 \n\t X", [ 123," \n\t ", "X"] ],
[ "%4s%2c%c", "1.2x\n\ny", [ "1.2x", "\n\n","y"] ],
[ "%f%c %3c%d", "1.2x\n\ny123", [ 1.2, "x", "y12", 3 ] ],
[ "%s%5c", "abc ab\ncd", [ "abc", " ab\nc" ] ],
[ "%5c%f", "ab\ncd1.2", [ "ab\ncd",1.2 ] ],
[ "%5c%c", "ab\ncd1", [ "ab\ncd","1" ] ],
[ "%f%c%2c%d", "1.2x\ny123", [ 1.2, "x", "\ny", 123 ] ],
[ "%f%c%3c", "1.2x\ny123", [ 1.2, "x", "\ny1"] ],
[ "%s\n%s", "blah\n\nand\nmore stuff", [ "blah", "and" ] ],
[ "%o%d%x", "21912a3", [ "21".oct, 912, "a3".hex ] ],
[ "%3o%4d%3x", "21912a3", [ "21".oct, 912, "a3".hex ] ],
[ "%3o%4d%5x", "2191240xa3", [ "21".oct, 9124, "a3".hex ] ],
[ "%3d%3x", "12abc", [12, "abc".hex] ],
[ "%s%i%d", "hello +0xdef 123", [ "hello", "def".hex, 123] ],
[ "%s%i%d", "hello -0xdef 123", [ "hello", -"def".hex, 123] ],
[ "%s%i%i%i%i", "hello 012 -012 100 1", [ "hello", 10, -10, 100, 1 ] ],
[ "%s%i%i%i%i", "hello 012 0x12 100 1", [ "hello", 10, 18, 100, 1 ] ],
[ "%s%5i%3i%4i", "hello 0x123 123 0123", [ "hello", "0x123".hex, 123,"0123".oct] ],
[ "%s%3i%4i", "hello 1230123", [ "hello", 123,"0123".oct] ],
[ "%s%3i", "hello 1230", [ "hello", 123] ],
[ "%s%5x%d", "hello 0xdef 123", [ "hello", "def".hex, 123] ],
[ "%s%6x%d", "hello +0xdef 123", [ "hello", "def".hex, 123] ],
[ "%s%6x%d", "hello -0xdef 123", [ "hello", -"def".hex, 123] ],
[ "%s%4x%d", "hello -def 123", [ "hello", -"def".hex, 123] ],
[ "%s%3x%d", "hello def 123", [ "hello", "def".hex, 123] ],
[ "%s%x%d", "hello -def 123", [ "hello", -"def".hex, 123] ],
[ "%s%x%d", "hello -0xdef 123", [ "hello", -"def".hex, 123] ],
[ "%s%x%d", "hello 0xdef 123", [ "hello", "def".hex, 123] ],
[ "%s%d%x%s", "hello 123 abc def", [ "hello", 123, "abc".hex, "def"] ],
[ "%s%d%o%d", "hello 012 012 100", [ "hello", 12, 10, 100 ] ],
[ "%s%d%o%d", "hello 012 -012 100", [ "hello", 12, -10, 100 ] ],
[ "%s%o%x%d", "hello 012 0x12 100", [ "hello", 10, 18, 100 ] ],
[ "%s%d%o%d", "hello 012 +01288", [ "hello", 12, 10, 88 ] ],
[ "%f %d %s", "12.3e23 45 string", ["12.3e23".to_f, 45, "string"] ],
[ "%f %d %s", "12.3e+23 45 string", ["12.3e23".to_f, 45, "string"] ],
[ "%f %d %s", "12.3e-23 45 string", ["12.3e-23".to_f, 45, "string"] ],
[ "%f %d %s", "-12.3e-23 45 string", ["-12.3e-23".to_f, 45, "string"] ],
[ "%f %d %s", "12.e23 45 string", ["12.e23".to_f, 45, "string"] ],
[ "%5f %d %s", "1.2e23 string", ["1.2e2".to_f, 3, "string"] ],
[ "%5f%d %s", "1.2e23 string", ["1.2e2".to_f, 3, "string"] ],
[ "%5f%d %d %s", "1.2e23 45 string", ["1.2e2".to_f, 3, 45, "string"] ],
[ "%6f %d %d %s", "+1.2e23 45 string", ["1.2e2".to_f, 3, 45, "string"] ],
[ "%d %d", "123 \n 345", [123, 345] ],
[ "%d %*d", "123 \n 345", [123] ],
[ "%d %3d789", "123 +45789", [123, 45] ],
[ "%d %3d%d", "123 +456789", [123, 45, 6789] ],
[ "%d %3dabc", "123 456abc", [123, 456] ],
[ "%d %s", "123abc", [123, "abc"] ],
[ "%d%s %s", "123 abc def", [123, "abc", "def"] ],
[ "%s%s", "abc123 def", ["abc123", "def"] ],
[ "%s%s %s", "123 abc def", ["123", "abc", "def"] ],
[ "%s%%%s", "abc % def", ["abc", "def"] ],
[ "%d %3d %s", "+123 456abc", [123, 456, "abc"] ],
[ "%d %3d %s", "123 456abc", [123, 456, "abc"] ],
[ "%d %3d %s", "123 +456 abc", [123, 45, "6"] ],
[ "%d %3d %s", "-123-456abc", [-123, -45, "6abc"] ],
[ "%dabc%d", "123abc345", [123, 345] ],
[ "%d%5s%d", "123 abcde12", [123, "abcde", 12] ],
[ "%5d%5s%5d", "12345abcde67890", [12345, "abcde", 67890] ],
[ "%5d%*5s%5d", "12345abcde67890", [12345, 67890] ],
[ " 12345%5s%5d", "12345abcde67890", [ "abcde", 67890] ],
[ "%5dabcde%5d", "12345abcde67890", [ 12345, 67890] ],
[ "%s%%%*s", "abc % def", ["abc"] ],
[ "%*6s %d", "string 123", [123] ],
[ "%d %*3d %s", "-123-456abc", [-123, "6abc"] ],
[ "%d%s", "123", [123] ],
[ "%s%d", "abc", ["abc"] ],
[ "%f%x", "3.2e45x", ["3.2e45x".to_f] ],
[ "%*5f%d %d %s", "1.2e23 45 string", [3, 45, "string"] ],
[ "%5f%*d %d %s", "1.2e23 45 string", ["1.2e2".to_f, 45, "string"] ],
[ "%*5f%*d %*d %s", "1.2e23 45 string", ["string"] ],
[ "%f %*d %s", "12.e23 45 string", ["12.e23".to_f, "string"] ],
[ "%s %f %s %d %x%c%c%c%c",
"float: 1.2e23 dec/hex: 135a23 abc",
["float:", "1.2e23".to_f, "dec/hex:", 135, "a23".hex, " ", "a", "b", "c" ] ],
# Testing 's'
[ "%s\n", "blah\n\n\n", [ "blah" ] ],
# Testing '['
[ "%[a\nb]", "a\nb", [ "a\nb" ] ],
[ "%[abc]", "acb", [ "acb" ] ],
[ "%[abc\n]", "a\nb", [ "a\nb" ] ],
[ "%[^abc]", "defabc", [ "def" ] ],
[ "%[-abc]", "abc-cba", [ "abc-cba" ] ],
[ "%[\n]", "\n", [ "\n" ] ],
[ "%[\n]", "\nabc", [ "\n" ] ],
[ "%[\n\t]", "\t\n", [ "\t\n" ] ],
[ "%[a-f]", "abczef", [ "abc" ] ],
[ "%d%3[[:lower:]] %f", "123ade1.2", [ 123,"ade",1.2 ] ],
[ "%d%3[[:lower:]] %f", "123ad1.2", [ 123,"ad",1.2 ] ],
[ "%d%3[[:lower:]] %f", "123 ad1.2", [ 123 ] ],
[ "%d%[[:lower:]]", "123abcdef1.2", [ 123, "abcdef" ] ],
[ "%[[:lower:]]%d", "abcdef123", [ "abcdef", 123 ] ],
[ "%[[:digit:]]%[[:alpha:]]", "123abcdef", [ "123", "abcdef" ] ],
[ "%[[:digit:]]%d", "123 123", [ "123", 123 ] ],
[ "%[[:upper:]]", "ABCdefGHI", [ "ABC" ] ],
# Testing 'f'
[ "%2f", "x", [] ],
[ "%F", "1.23e45", [1.23e+45] ],
[ "%e", "3.25ee", [3.25] ],
[ "%E", "3..25", [3.0] ],
[ "%g", "+3.25", [3.25] ],
[ "%G", "+3.25e2", [325.0] ],
[ "%f", "3.z", [3.0] ],
[ "%a", "0X1P+10", [1024.0] ],
[ "%a", "0X1P10", [1024.0] ],
[ "%A", "0x1.deadbeefp+99", [1.1851510441583988e+30] ],
# Testing embedded matches including literal '[' behavior
[",%d,%f", ",10,1.1", [10,1.1] ],
[" ,%d,%f", " ,10,1.1", [10,1.1] ],
["[%d,%f", "[10,1.1", [10,1.1] ],
[" [%d,%f", " [10,1.1", [10,1.1] ],
]
end
def each_test
self.tests.each do |test|
format, string, = test
yield test, "#{string.dump}(#{format.dump})"
end
end
end
class TestStringScanf
include Scanf
extend ScanfTests
self.each_test do |test, i|
define_method("test_#{i}") do ||
assert_equal(test[2], test[1].scanf(test[0]))
end
end
end
class TestIOScanf
include Scanf
extend ScanfTests
self.each_test do |test, i|
define_method("test_#{i}") do ||
Tempfile.create("iotest.dat") do |fh|
fh.print test[1]
fh.rewind
assert_equal(test[2], fh.scanf(test[0]))
end
end
end
end

@ -0,0 +1,82 @@
# frozen_string_literal: false
# $Id$
#
# scanf for Ruby
#
# Some not very comprehensive tests of block behavior.
require 'test/unit'
require 'scanf'
require 'tmpdir'
class TestScanfBlock < Test::Unit::TestCase
def setup
@str = <<-EOS
Beethoven 1770
Bach 1685
Handel 1685
Scarlatti 1685
Brahms 1833
EOS
end
alias set_up setup
def test_str1
res = @str.scanf("%s%d") { |name, year| "#{name} was born in #{year}." }
assert_equal(res,
[ "Beethoven was born in 1770.",
"Bach was born in 1685.",
"Handel was born in 1685.",
"Scarlatti was born in 1685.",
"Brahms was born in 1833." ])
end
def test_str2
names = @str.scanf("%s%d") { |name, year| name.upcase }
assert_equal(names, ["BEETHOVEN", "BACH", "HANDEL", "SCARLATTI", "BRAHMS"])
end
def test_str3
assert_equal("".scanf("%d%f%s") {}, [])
end
def test_str4
assert_equal("abc".scanf("%d%f%s") {}, [])
end
def test_str5
assert_equal("abc".scanf("") {}, [])
end
def test_io1
fn = "#{Dir.tmpdir}/iotest.dat.#{$$}"
File.open(fn, "w") { |fh| fh.puts(@str) }
fh = File.open(fn, "rb")
res = fh.scanf("%s%d") { |name, year| "#{name} was born in #{year}." }
assert_equal(
[ "Beethoven was born in 1770.",
"Bach was born in 1685.",
"Handel was born in 1685.",
"Scarlatti was born in 1685.",
"Brahms was born in 1833." ],res)
fh.close
ensure
File.delete(fn)
end
def test_io2
fn = "#{Dir.tmpdir}/iotest.dat.#{$$}"
File.open(fn, "w").close
fh = File.open(fn,"rb")
assert_equal(fh.scanf("") {}, [])
fh.seek(0)
assert_equal(fh.scanf("%d%f%s") {}, [])
fh.close
ensure
File.delete(fn)
end
end

@ -0,0 +1,28 @@
# frozen_string_literal: false
# $Id$
#
# scanf for Ruby
#
# Ad hoc tests of IO#scanf (needs to be expanded)
require "scanf"
class TestScanfIO < Test::Unit::TestCase
def test_io
fh = File.new(File.join(File.dirname(__FILE__), "data.txt"), "r")
assert_equal(0, fh.pos)
assert_equal(["this", "is"], fh.scanf("%s%s"))
assert_equal([33, "little"], fh.scanf("%da fun%s"))
ensure
fh.close
end
def test_pipe_scanf
r, w = IO.pipe
w.write('a')
w.close
assert_equal([], r.scanf('a'))
end
end
Loading…
Cancel
Save