Commit 24e5f24097e6985512f4bbfe9c0c7a0ab3c4f5b0

Thomas de Grivel 2023-04-10T23:19:38

buf_parse_test_{s,u}

diff --git a/test/buf_parse_test_s.rb b/test/buf_parse_test_s.rb
index 1835e9c..a360ded 100644
--- a/test/buf_parse_test_s.rb
+++ b/test/buf_parse_test_s.rb
@@ -1,20 +1,38 @@
 File.open("buf_parse_test_s.out", "w") do |out|
-  result = 0
-  base = 0..7
-  base_prefix = "0o"
-  negative = "-"
-  base.each do |i|
-    base.each do |j|
-      base.each do |k|
-        if (i == 0 && j == 0)
-          out.puts "  BUF_PARSE_TEST_S(8, \"#{negative}#{base_prefix}#{k}\", #{negative}#{result});"
+  ["S", "U"].each do |su|
+    [8].each do |bits|
+      out.puts "void buf_parse_test_#{su.downcase}#{bits} ()"
+      out.puts "{"
+      [[0..1, "0b"],
+       [0..7, "0o"],
+       [0..15, "0x"],
+       [0..10, ""]].each do |b|
+        base = b[0]
+        base_prefix = b[1]
+        signs = if (su == "S")
+                  ["-", ""]
+                else
+                  [""]
+                end
+        signs.each do |negative|
+          result = 0
+          base.each do |i|
+            base.each do |j|
+              base.each do |k|
+                if (i == 0 && j == 0)
+                  out.puts "  BUF_PARSE_TEST_#{su}(#{bits}, \"#{negative}#{base_prefix}#{k}\",   #{negative}#{result});"
+                end
+                if (i == 0)
+                  out.puts "  BUF_PARSE_TEST_#{su}(#{bits}, \"#{negative}#{base_prefix}#{j}#{k}\",  #{negative}#{result});"
+                end
+                out.puts "  BUF_PARSE_TEST_#{su}(#{bits}, \"#{negative}#{base_prefix}#{i}#{j}#{k}\", #{negative}#{result});"
+                result += 1
+              end
+            end
+          end
         end
-        if (i == 0)
-          out.puts "  BUF_PARSE_TEST_S(8, \"#{negative}#{base_prefix}#{j}#{k}\", #{negative}#{result});"
-        end
-        out.puts "  BUF_PARSE_TEST_S(8, \"#{negative}#{base_prefix}#{i}#{j}#{k}\", #{negative}#{result});"
-        result += 1
       end
+      out.puts "}"
     end
   end
 end