diff mbox series

[v3,35/35] userdiff tests: add basic test for ruby

Message ID 20210224195129.4004-36-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series userdiff: refactor + test + doc + misc improvements | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 24, 2021, 7:51 p.m. UTC
Add a test for the Ruby pattern added way back in ad8c1d9260 (diff:
add ruby funcname pattern, 2008-07-31).

The "One/Two" picking demonstrates existing behavior, and a general
case where we may not do what the user expects since we're not aware
of the indentation level.

The code is modified from the Ruby code we have in-tree at
Documentation/asciidoctor-extensions.rb.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t4018-diff-funcname.sh |  1 -
 t/t4018/ruby.sh          | 58 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100755 t/t4018/ruby.sh

Comments

Johannes Sixt Feb. 27, 2021, 7:30 a.m. UTC | #1
Am 24.02.21 um 20:51 schrieb Ævar Arnfjörð Bjarmason:
> Add a test for the Ruby pattern added way back in ad8c1d9260 (diff:
> add ruby funcname pattern, 2008-07-31).
> 
> The "One/Two" picking demonstrates existing behavior, and a general
> case where we may not do what the user expects since we're not aware
> of the indentation level.
> 
> The code is modified from the Ruby code we have in-tree at
> Documentation/asciidoctor-extensions.rb.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t4018-diff-funcname.sh |  1 -
>  t/t4018/ruby.sh          | 58 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 58 insertions(+), 1 deletion(-)
>  create mode 100755 t/t4018/ruby.sh
> 
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index b0c2782d067..7793d7652d5 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -23,7 +23,6 @@ test_expect_success 'setup' '
>  	html
>  	objc
>  	pascal
> -	ruby
>  	tex
>  	EOF
>  
> diff --git a/t/t4018/ruby.sh b/t/t4018/ruby.sh
> new file mode 100755
> index 00000000000..ef8a154421a
> --- /dev/null
> +++ b/t/t4018/ruby.sh
> @@ -0,0 +1,58 @@
> +#!/bin/sh
> +#
> +# See ../t4018-diff-funcname.sh's test_diff_funcname()
> +#
> +
> +test_diff_funcname 'ruby: "def" over "class/module"' \
> +	8<<\EOF_HUNK 9<<\EOF_TEST
> +def process(parent)
> +EOF_HUNK
> +require 'asciidoctor'
> +
> +module Git
> +  module Documentation
> +    class SomeClass
> +      use_some
> +
> +      def process(parent)
> +        puts("hello")
> +	puts(ChangeMe)
> +      end
> +    end
> +  end
> +end
> +EOF_TEST
> +
> +test_diff_funcname 'ruby: "class" over "class/module"' \
> +	8<<\EOF_HUNK 9<<\EOF_TEST
> +class Two
> +EOF_HUNK
> +module Git
> +  module Documentation
> +    class One
> +    end
> +
> +    class Two
> +      # Spacing for -U1

Again: -U0 is the default by now.

> +      ChangeMe
> +    end
> +  end
> +end
> +EOF_TEST
> +
> +test_diff_funcname 'ruby: picks first "class/module/def" before changed context' \
> +	'-U1' \
> +	8<<\EOF_HUNK 9<<\EOF_TEST
> +class One
> +EOF_HUNK
> +module Git
> +  module Documentation
> +    class One
> +    end
> +
> +    class Two
> +      ChangeMe
> +    end
> +  end
> +end
> +EOF_TEST

Why does this test need -U1? Wouldn't it be sufficient to change the
expected text to "class Two"? And if the answer is "yes", I again do not
see the need for a shell script test here; the simplified version would do.

-- Hannes
diff mbox series

Patch

diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index b0c2782d067..7793d7652d5 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -23,7 +23,6 @@  test_expect_success 'setup' '
 	html
 	objc
 	pascal
-	ruby
 	tex
 	EOF
 
diff --git a/t/t4018/ruby.sh b/t/t4018/ruby.sh
new file mode 100755
index 00000000000..ef8a154421a
--- /dev/null
+++ b/t/t4018/ruby.sh
@@ -0,0 +1,58 @@ 
+#!/bin/sh
+#
+# See ../t4018-diff-funcname.sh's test_diff_funcname()
+#
+
+test_diff_funcname 'ruby: "def" over "class/module"' \
+	8<<\EOF_HUNK 9<<\EOF_TEST
+def process(parent)
+EOF_HUNK
+require 'asciidoctor'
+
+module Git
+  module Documentation
+    class SomeClass
+      use_some
+
+      def process(parent)
+        puts("hello")
+	puts(ChangeMe)
+      end
+    end
+  end
+end
+EOF_TEST
+
+test_diff_funcname 'ruby: "class" over "class/module"' \
+	8<<\EOF_HUNK 9<<\EOF_TEST
+class Two
+EOF_HUNK
+module Git
+  module Documentation
+    class One
+    end
+
+    class Two
+      # Spacing for -U1
+      ChangeMe
+    end
+  end
+end
+EOF_TEST
+
+test_diff_funcname 'ruby: picks first "class/module/def" before changed context' \
+	'-U1' \
+	8<<\EOF_HUNK 9<<\EOF_TEST
+class One
+EOF_HUNK
+module Git
+  module Documentation
+    class One
+    end
+
+    class Two
+      ChangeMe
+    end
+  end
+end
+EOF_TEST