From bc1a5db6cc103f125a3705970d0018fb145aca4a Mon Sep 17 00:00:00 2001 From: Stéphane Campinas Date: Sat, 10 Sep 2016 20:35:47 +0100 Subject: vim-patch:7.4.1547 #5326 Problem: Getting a cterm highlight attribute that is not set results in the string "-1". Solution: Return an empty string. (Taro Muraoka) https://github.com/vim/vim/commit/385111bd86e0b38667879c3e89506ca1ae98e1df --- src/nvim/syntax.c | 10 +++++++--- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_syn_attr.vim | 31 +++++++++++++++++++++++++++++++ src/nvim/version.c | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/nvim/testdir/test_syn_attr.vim (limited to 'src') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index c753c6fabd..6fd7603629 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -7001,11 +7001,15 @@ highlight_color ( if (font || sp) return NULL; if (modec == 'c') { - if (fg) + if (fg) { n = HL_TABLE()[id - 1].sg_cterm_fg - 1; - else + } else { n = HL_TABLE()[id - 1].sg_cterm_bg - 1; - sprintf((char *)name, "%d", n); + } + if (n < 0) { + return NULL; + } + snprintf((char *)name, sizeof(name), "%d", n); return name; } /* term doesn't have color */ diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index e5214971b4..f0efd6e4ed 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -8,4 +8,5 @@ source test_cmdline.vim source test_menu.vim source test_popup.vim source test_regexp_utf8.vim +source test_syn_attr.vim source test_unlet.vim diff --git a/src/nvim/testdir/test_syn_attr.vim b/src/nvim/testdir/test_syn_attr.vim new file mode 100644 index 0000000000..20e9b17c46 --- /dev/null +++ b/src/nvim/testdir/test_syn_attr.vim @@ -0,0 +1,31 @@ +" Test syntax highlighting functions. + +func Test_missing_attr() + hi Mine term=bold cterm=italic + call assert_equal('Mine', synIDattr(hlID("Mine"), "name")) + call assert_equal('', synIDattr(hlID("Mine"), "bg", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "bold", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "italic", 'cterm')) + hi Mine term=reverse cterm=inverse + call assert_equal('1', synIDattr(hlID("Mine"), "reverse", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm')) + hi Mine term=underline cterm=standout gui=undercurl + call assert_equal('1', synIDattr(hlID("Mine"), "underline", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm')) + call assert_equal('1', synIDattr(hlID("Mine"), "undercurl", 'gui')) + hi Mine term=NONE cterm=NONE gui=NONE + call assert_equal('', synIDattr(hlID("Mine"), "bold", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "italic", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "reverse", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "inverse", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "underline", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "standout", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "undercurl", 'gui')) + + if has('gui') + hi Mine guifg=blue guibg=red font=something + call assert_equal('blue', synIDattr(hlID("Mine"), "fg", 'gui')) + call assert_equal('red', synIDattr(hlID("Mine"), "bg", 'gui')) + call assert_equal('something', synIDattr(hlID("Mine"), "font", 'gui')) + endif +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index bc826d8660..fa949224f3 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -730,7 +730,7 @@ static int included_patches[] = { 1550, // 1549, 1548, - // 1547, + 1547, 1546, // 1545 NA // 1544 NA -- cgit From 21eee40cdbe77d4d2095db14b5b7f8de27a5ae52 Mon Sep 17 00:00:00 2001 From: Stéphane Campinas Date: Sun, 11 Sep 2016 15:03:22 +0100 Subject: test: synIDattr returns empty, not -1 - Behavior changed in 7.4.1547 - Also removed N/A specs: nvim does not support ":hi term=..." --- src/nvim/testdir/test_syn_attr.vim | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_syn_attr.vim b/src/nvim/testdir/test_syn_attr.vim index 20e9b17c46..809442eb94 100644 --- a/src/nvim/testdir/test_syn_attr.vim +++ b/src/nvim/testdir/test_syn_attr.vim @@ -1,24 +1,17 @@ " Test syntax highlighting functions. func Test_missing_attr() - hi Mine term=bold cterm=italic + hi Mine cterm=italic call assert_equal('Mine', synIDattr(hlID("Mine"), "name")) - call assert_equal('', synIDattr(hlID("Mine"), "bg", 'term')) - call assert_equal('1', synIDattr(hlID("Mine"), "bold", 'term')) call assert_equal('1', synIDattr(hlID("Mine"), "italic", 'cterm')) - hi Mine term=reverse cterm=inverse - call assert_equal('1', synIDattr(hlID("Mine"), "reverse", 'term')) + hi Mine cterm=inverse call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm')) - hi Mine term=underline cterm=standout gui=undercurl - call assert_equal('1', synIDattr(hlID("Mine"), "underline", 'term')) + hi Mine cterm=standout gui=undercurl call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm')) call assert_equal('1', synIDattr(hlID("Mine"), "undercurl", 'gui')) - hi Mine term=NONE cterm=NONE gui=NONE - call assert_equal('', synIDattr(hlID("Mine"), "bold", 'term')) + hi Mine cterm=NONE gui=NONE call assert_equal('', synIDattr(hlID("Mine"), "italic", 'cterm')) - call assert_equal('', synIDattr(hlID("Mine"), "reverse", 'term')) call assert_equal('', synIDattr(hlID("Mine"), "inverse", 'cterm')) - call assert_equal('', synIDattr(hlID("Mine"), "underline", 'term')) call assert_equal('', synIDattr(hlID("Mine"), "standout", 'cterm')) call assert_equal('', synIDattr(hlID("Mine"), "undercurl", 'gui')) -- cgit