Re: Patch 8.0.1656

2018-04-06 Fir de Conversatie Christian Brabandt

On Fr, 06 Apr 2018, Bram Moolenaar wrote:

> It might be good to check if xxd was actually built. The normal "make"
> command should, but some people might use their own way of building.
> A missing "xxd" executable should not make the test fail.

Yeah, initially, I wanted to make the test depend on src/xxd/xxd 

But I couldn't figure out how to make it depend on a rule from a 
different Makefile, so I left it as is. So here is an update that simply 
checks if $XXD is executable.

Best,
Christian
-- 
Die größten Ereignisse, das sind nicht unsere lautesten, sondern
unsere stillsten Stunden.
-- Friedrich Wilhelm Nietzsche

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
From a5cda5454aa8cd297249f75dcb880e8882dba53e Mon Sep 17 00:00:00 2001
From: Christian Brabandt 
Date: Thu, 5 Apr 2018 23:26:03 +0200
Subject: [PATCH] Add a test for xxd

---
 src/testdir/Make_all.mak |  1 +
 src/testdir/Makefile |  4 ++
 src/testdir/test_xxd.vim | 95 
 3 files changed, 100 insertions(+)
 create mode 100644 src/testdir/test_xxd.vim

diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 159bf1ece..b4e4bc328 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -187,6 +187,7 @@ NEW_TESTS = test_arabic.res \
 	test_windows_home.res \
 	test_wordcount.res \
 	test_writefile.res \
+	test_xxd.res \
 	test_alot_latin.res \
 	test_alot_utf8.res \
 	test_alot.res
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index 2ff72c230..fe36a4e05 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -4,6 +4,7 @@
 
 # Use console or GUI.
 VIMPROG = ../vim
+XXDPROG = ../xxd/xxd
 # VIMPROG = ../gvim
 
 SCRIPTSOURCE = ../../runtime
@@ -145,3 +146,6 @@ test_gui_init.res: test_gui_init.vim
 
 opt_test.vim: ../option.c gen_opt_test.vim
 	$(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c
+
+test_xxd.res:
+	XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim
diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim
new file mode 100644
index 0..c0ed06ae8
--- /dev/null
+++ b/src/testdir/test_xxd.vim
@@ -0,0 +1,95 @@
+" Test for the xxd command
+func! PrepareBuffer(command)
+  %d
+  call append(0, a:command)
+  $d
+  w Xfile
+endfunc
+
+func! s:Mess(counter)
+  return printf("Failed xxd test %d:", a:counter)
+endfunc
+
+func! Test_xxd()
+  if empty($XXD) || !executable($XXD)
+return
+  endif
+  new
+  let s:test=0
+  call PrepareBuffer(range(1,30))
+  " Test 1: simple, filter the result through xxd
+  let s:test+=1
+  let msg=printf("Failed xxd test %d:", s:test)
+  %!$XXD %
+  let expected=[
+\ ': 310a 320a 330a 340a 350a 360a 370a 380a  1.2.3.4.5.6.7.8.',
+\ '0010: 390a 3130 0a31 310a 3132 0a31 330a 3134  9.10.11.12.13.14',
+\ '0020: 0a31 350a 3136 0a31 370a 3138 0a31 390a  .15.16.17.18.19.',
+\ '0030: 3230 0a32 310a 3232 0a32 330a 3234 0a32  20.21.22.23.24.2',
+\ '0040: 350a 3236 0a32 370a 3238 0a32 390a 3330  5.26.27.28.29.30',
+\ '0050: 0a   .']
+  call assert_equal(expected, getline(1,'$'), msg)
+  " Test 2: reverse the result
+  let s:test+=1
+  %!$XXD -r
+  call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
+
+  " Test 3: Skip the first 30 bytes
+  let s:test+=1
+  %!$XXD -s 0x30 %
+  call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
+
+  " Test 4: Skip the first 30 bytes
+  let s:test+=1
+  %!$XXD -s -0x31 %
+  call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
+
+  " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
+  let s:test+=1
+  %d
+  0r! $XXD -l 120 -ps -c 20 ../../runtime/doc/xxd.1
+  $d
+  let expected=[
+  \ '2e54482058584420312022417567757374203139',
+  \ '39362220224d616e75616c207061676520666f72',
+  \ '20787864220a2e5c220a2e5c222032317374204d',
+  \ '617920313939360a2e5c22204d616e2070616765',
+  \ '20617574686f723a0a2e5c2220202020546f6e79',
+  \ '204e7567656e74203c746f6e79407363746e7567']
+  call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+  " Test 6: Print the date from xxd.1
+  let s:test+=1
+  %d
+  0r! $XXD -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1
+  $d
+  call assert_equal('0036: 3231 7374 204d 6179 2031 3939 36  21st May 1996', getline(1), s:Mess(s:test))
+  " Test 7: Print C include
+  let s:test+=1
+  call writefile(['TESTabcd09'], 

Re: Patch 8.0.1656

2018-04-06 Fir de Conversatie Bram Moolenaar

Christian Brabandt wrote:

> On Di, 03 Apr 2018, Christian Brabandt wrote:
> 
> > 
> > On Di, 03 Apr 2018, Bram Moolenaar wrote:
> > 
> > > And we should have a test for xxd some day.
> > 
> > I'll have a look.
> 
> How about the following basic test?

Thanks!

It might be good to check if xxd was actually built. The normal "make"
command should, but some people might use their own way of building.
A missing "xxd" executable should not make the test fail.


-- 
In a world without walls and borders, who needs windows and gates?

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 8.0.1656

2018-04-05 Fir de Conversatie Christian Brabandt

On Di, 03 Apr 2018, Christian Brabandt wrote:

> 
> On Di, 03 Apr 2018, Bram Moolenaar wrote:
> 
> > And we should have a test for xxd some day.
> 
> I'll have a look.

How about the following basic test?

Best,
Christian
-- 
Gegensätze ziehen sich an - z.B. arme Mädchen und reiche Männer.
-- Jayne Mansfield

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
From 31f8922dce3918fa27d458b8c053e99cb0567198 Mon Sep 17 00:00:00 2001
From: Christian Brabandt 
Date: Thu, 5 Apr 2018 23:26:03 +0200
Subject: [PATCH] Add a test for xxd

---
 src/testdir/Make_all.mak |  1 +
 src/testdir/Makefile |  4 +++
 src/testdir/test_xxd.vim | 92 
 3 files changed, 97 insertions(+)
 create mode 100644 src/testdir/test_xxd.vim

diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 159bf1ece..b4e4bc328 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -187,6 +187,7 @@ NEW_TESTS = test_arabic.res \
 	test_windows_home.res \
 	test_wordcount.res \
 	test_writefile.res \
+	test_xxd.res \
 	test_alot_latin.res \
 	test_alot_utf8.res \
 	test_alot.res
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index 2ff72c230..fe36a4e05 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -4,6 +4,7 @@
 
 # Use console or GUI.
 VIMPROG = ../vim
+XXDPROG = ../xxd/xxd
 # VIMPROG = ../gvim
 
 SCRIPTSOURCE = ../../runtime
@@ -145,3 +146,6 @@ test_gui_init.res: test_gui_init.vim
 
 opt_test.vim: ../option.c gen_opt_test.vim
 	$(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c
+
+test_xxd.res:
+	XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim
diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim
new file mode 100644
index 0..679d6cab2
--- /dev/null
+++ b/src/testdir/test_xxd.vim
@@ -0,0 +1,92 @@
+" Test for the xxd command
+func! PrepareBuffer(command)
+  %d
+  call append(0, a:command)
+  $d
+  w Xfile
+endfunc
+
+func! s:Mess(counter)
+  return printf("Failed xxd test %d:", a:counter)
+endfunc
+
+func! Test_xxd()
+  new
+  let s:test=0
+  call PrepareBuffer(range(1,30))
+  " Test 1: simple, filter the result through xxd
+  let s:test+=1
+  let msg=printf("Failed xxd test %d:", s:test)
+  %!$XXD %
+  let expected=[
+\ ': 310a 320a 330a 340a 350a 360a 370a 380a  1.2.3.4.5.6.7.8.',
+\ '0010: 390a 3130 0a31 310a 3132 0a31 330a 3134  9.10.11.12.13.14',
+\ '0020: 0a31 350a 3136 0a31 370a 3138 0a31 390a  .15.16.17.18.19.',
+\ '0030: 3230 0a32 310a 3232 0a32 330a 3234 0a32  20.21.22.23.24.2',
+\ '0040: 350a 3236 0a32 370a 3238 0a32 390a 3330  5.26.27.28.29.30',
+\ '0050: 0a   .']
+  call assert_equal(expected, getline(1,'$'), msg)
+  " Test 2: reverse the result
+  let s:test+=1
+  %!$XXD -r
+  call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
+
+  " Test 3: Skip the first 30 bytes
+  let s:test+=1
+  %!$XXD -s 0x30 %
+  call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
+
+  " Test 4: Skip the first 30 bytes
+  let s:test+=1
+  %!$XXD -s -0x31 %
+  call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
+
+  " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
+  let s:test+=1
+  %d
+  0r! $XXD -l 120 -ps -c 20 ../../runtime/doc/xxd.1
+  $d
+  let expected=[
+  \ '2e54482058584420312022417567757374203139',
+  \ '39362220224d616e75616c207061676520666f72',
+  \ '20787864220a2e5c220a2e5c222032317374204d',
+  \ '617920313939360a2e5c22204d616e2070616765',
+  \ '20617574686f723a0a2e5c2220202020546f6e79',
+  \ '204e7567656e74203c746f6e79407363746e7567']
+  call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+  " Test 6: Print the date from xxd.1
+  let s:test+=1
+  %d
+  0r! $XXD -s 0x36 -l 13 -c 13 ../../runtime/doc/xxd.1
+  $d
+  call assert_equal('0036: 3231 7374 204d 6179 2031 3939 36  21st May 1996', getline(1), s:Mess(s:test))
+  " Test 7: Print C include
+  let s:test+=1
+  call writefile(['TESTabcd09'], 'Xfile')
+  %d
+  0r! $XXD -i Xfile
+  $d
+  let expected=['unsigned char Xfile[] = {',
+\ '  0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};',
+\ 'unsigned int Xfile_len = 11;']
+  call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
+  " Test 8: Print C include capitalized
+  let s:test+=1
+  call writefile(['TESTabcd09'], 

Re: Patch 8.0.1656

2018-04-03 Fir de Conversatie Christian Brabandt

On Di, 03 Apr 2018, Bram Moolenaar wrote:

> And we should have a test for xxd some day.

I'll have a look.

Best,
Christian
-- 
Aus Murphy's Gesetze:
"Drag und drop" ist die Methode, etwas sehr langsam und mühevoll über
den Bildschirm zu bewegen. Animation auch.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 8.0.1656

2018-04-03 Fir de Conversatie Bram Moolenaar

Christian wrote:

> On Di, 03 Apr 2018, Bram Moolenaar wrote:
> 
> > Patch 8.0.1656
> > Problem:No option to have xxd produce upper case variable names.
> > Solution:   Add the -C argument. (Matt Panaro closes #2772)
> > Files:  src/xxd/xxd.c
> 
> Shouldn't the mangpage also be adjusted?

Yeah.  Should probably also support the long form argument.
And we should have a test for xxd some day.

-- 
I AM THANKFUL...
...for the mess to clean after a party because it means I have
been surrounded by friends.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Patch 8.0.1656

2018-04-03 Fir de Conversatie Christian Brabandt

On Di, 03 Apr 2018, Bram Moolenaar wrote:

> Patch 8.0.1656
> Problem:No option to have xxd produce upper case variable names.
> Solution:   Add the -C argument. (Matt Panaro closes #2772)
> Files:  src/xxd/xxd.c

Shouldn't the mangpage also be adjusted?

Best,
Christian
-- 
Geiz läßt sich nicht improvisieren.
-- Yvan Goll

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Patch 8.0.1656

2018-04-03 Fir de Conversatie Bram Moolenaar

Patch 8.0.1656
Problem:No option to have xxd produce upper case variable names.
Solution:   Add the -C argument. (Matt Panaro closes #2772)
Files:  src/xxd/xxd.c


*** ../vim-8.0.1655/src/xxd/xxd.c   2018-02-24 18:30:51.173639406 +0100
--- src/xxd/xxd.c   2018-04-03 12:13:21.949306422 +0200
***
*** 215,220 
--- 215,222 
  #define HEX_BITS 3/* not hex a dump, but bits: 0001 */
  #define HEX_LITTLEENDIAN 4
  
+ #define CONDITIONAL_CAPITALIZE(c) (capitalize ? toupper((int)c) : c)
+ 
  static char *pname;
  
static void
***
*** 225,230 
--- 227,233 
fprintf(stderr, "Options:\n");
fprintf(stderr, "-a  toggle autoskip: A single '*' replaces 
nul-lines. Default off.\n");
fprintf(stderr, "-b  binary digit dump (incompatible with 
-ps,-i,-r). Default hex.\n");
+   fprintf(stderr, "-C  capitalize variable names in C include 
file style (-i).\n");
fprintf(stderr, "-c cols format  octets per line. Default 16 
(-i: 12, -ps: 30).\n");
fprintf(stderr, "-E  show characters in EBCDIC. Default 
ASCII.\n");
fprintf(stderr, "-e  little-endian dump (incompatible with 
-ps,-i,-r).\n");
***
*** 459,465 
  {
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
!   int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
int ebcdic = 0;
int octspergrp = -1;/* number of octets grouped in output */
int grplen; /* total chars per octet group */
--- 462,468 
  {
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
!   int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 
0;
int ebcdic = 0;
int octspergrp = -1;/* number of octets grouped in output */
int grplen; /* total chars per octet group */
***
*** 495,500 
--- 498,504 
else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16;
else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT;
else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE;
+   else if (!STRNCMP(pp, "-C", 2)) capitalize = 1;
else if (!STRNCMP(pp, "-r", 2)) revert++;
else if (!STRNCMP(pp, "-E", 2)) ebcdic++;
else if (!STRNCMP(pp, "-v", 2))
***
*** 722,728 
  if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" 
: "") < 0)
die(3);
  for (e = 0; (c = argv[1][e]) != 0; e++)
!   if (putc(isalnum(c) ? c : '_', fpo) == EOF)
  die(3);
  if (fputs("[] = {\n", fpo) == EOF)
die(3);
--- 726,732 
  if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" 
: "") < 0)
die(3);
  for (e = 0; (c = argv[1][e]) != 0; e++)
!   if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
  die(3);
  if (fputs("[] = {\n", fpo) == EOF)
die(3);
***
*** 750,758 
  if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : 
"") < 0)
die(3);
  for (e = 0; (c = argv[1][e]) != 0; e++)
!   if (putc(isalnum(c) ? c : '_', fpo) == EOF)
  die(3);
! if (fprintf(fpo, "_len = %d;\n", p) < 0)
die(3);
}
  
--- 754,762 
  if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : 
"") < 0)
die(3);
  for (e = 0; (c = argv[1][e]) != 0; e++)
! if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
  die(3);
! if (fprintf(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p) < 0)
die(3);
}
  
*** ../vim-8.0.1655/src/version.c   2018-03-29 18:29:47.297127408 +0200
--- src/version.c   2018-04-03 12:16:52.224327009 +0200
***
*** 764,765 
--- 764,767 
  {   /* Add new patch number below this line */
+ /**/
+ 1656,
  /**/

-- 
>From "know your smileys":
 :-&Eating spaghetti

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.