From 27e908ff2a00d1637bb12bc8f592c577f135f137 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Thu, 26 Sep 2024 04:10:18 +0300 Subject: [PATCH] #138 more tests --- test/pages/test_awards.rb | 126 +++++++++++++++++++++++++------------- xsl/awards.xsl | 4 ++ 2 files changed, 86 insertions(+), 44 deletions(-) diff --git a/test/pages/test_awards.rb b/test/pages/test_awards.rb index 12bd3f0..38fe52f 100644 --- a/test/pages/test_awards.rb +++ b/test/pages/test_awards.rb @@ -33,6 +33,81 @@ # License:: MIT class TestAwards < Minitest::Test def test_payables + xml = xslt( + "", + " + + + reconciliation + #{(Time.now - (60 * 60)).utc.iso8601} + #{(Time.now - (50 * 60 * 60)).utc.iso8601} + dude + 100 + 70 + 30 + + + 1 + #{(Time.now - (10 * 60 * 60)).utc.iso8601} + dude + 40 + + + 1 + #{(Time.now - (10 * 60 * 60)).utc.iso8601} + dude + 60 + + + 1 + #{Time.now.utc.iso8601} + dude + 25 + + + ", + 'today' => (Time.now - (10 * 60 * 60)).utc.iso8601 + ) + assert_equal('55', xml.xpath('/td/text()').to_s, xml) + end + + def test_monday + xml = xslt( + '', + ' + + + pmp + hr + 7 + + + ', + 'today' => '2024-09-26T04:04:04Z' + ) + assert_equal('2024-09-23Z', xml.xpath('/r/text()').to_s, xml) + end + + def test_in_week + xml = xslt( + '', + ' + + + pmp + hr + 14 + + + ', + 'today' => '2024-09-26T04:04:04Z' + ) + assert_equal('true', xml.xpath('/r/text()').to_s, xml) + end + + private + + def xslt(template, xml, vars = {}) Dir.mktmpdir do |dir| xsl = File.join(dir, 'foo.xsl') File.write( @@ -42,60 +117,23 @@ def test_payables xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:z='https://www.zerocracy.com' version='2.0' exclude-result-prefixes='xs z'> - - - + #{template} " ) - xml = File.join(dir, 'input.xml') - File.write( - xml, - " - - - reconciliation - #{(Time.now - (60 * 60)).utc.iso8601} - #{(Time.now - (50 * 60 * 60)).utc.iso8601} - dude - 100 - 70 - 30 - - - 1 - #{(Time.now - (10 * 60 * 60)).utc.iso8601} - dude - 40 - - - 1 - #{(Time.now - (10 * 60 * 60)).utc.iso8601} - dude - 60 - - - 1 - #{Time.now.utc.iso8601} - dude - 25 - - - " - ) + input = File.join(dir, 'input.xml') + File.write(input, xml) output = File.join(dir, 'output.xml') qbash( [ "java -jar #{Shellwords.escape(File.join(__dir__, '../../target/saxon.jar'))}", - "-s:#{Shellwords.escape(xml)}", + "-s:#{Shellwords.escape(input)}", "-xsl:#{Shellwords.escape(xsl)}", - "-o:#{Shellwords.escape(output)}", - "today=#{Shellwords.escape((Time.now + 10).utc.iso8601)}" - ], + "-o:#{Shellwords.escape(output)}" + ] + vars.map { |k, v| Shellwords.escape("#{k}=#{v}") }, log: Loog::NULL ) - out = Nokogiri::XML.parse(File.read(output)) - assert_equal('55', out.xpath('/td/text()').to_s, out) + Nokogiri::XML.parse(File.read(output)) end end end diff --git a/xsl/awards.xsl b/xsl/awards.xsl index 139c861..90ef6f9 100644 --- a/xsl/awards.xsl +++ b/xsl/awards.xsl @@ -29,6 +29,10 @@ SOFTWARE. +