From 500761b1cf666f030009d2dcdacfdce28f68f43d Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 5 Feb 2022 20:23:59 +0000 Subject: patch 8.2.4306: no test for fixed perl filetype check Problem: No test for fixed perl filetype check. Solution: Add a test. Sort test functions. --- src/testdir/test_filetype.vim | 647 ++++++++++++++++++++++-------------------- src/version.c | 2 + 2 files changed, 336 insertions(+), 313 deletions(-) diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index b9909c648..13a494b96 100644 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -756,101 +756,126 @@ func Test_filetype_indent_off() close endfunc -func Test_hook_file() +""""""""""""""""""""""""""""""""""""""""""""""""" +" Tests for specific extentions and filetypes. +" Keep sorted. +""""""""""""""""""""""""""""""""""""""""""""""""" + +func Test_bas_file() filetype on - call writefile(['[Trigger]', 'this is pacman config'], 'Xfile.hook') - split Xfile.hook - call assert_equal('dosini', &filetype) + call writefile(['looks like BASIC'], 'Xfile.bas') + split Xfile.bas + call assert_equal('basic', &filetype) bwipe! - call writefile(['not pacman'], 'Xfile.hook') - split Xfile.hook - call assert_notequal('dosini', &filetype) + " Test dist#ft#FTbas() + + let g:filetype_bas = 'freebasic' + split Xfile.bas + call assert_equal('freebasic', &filetype) bwipe! + unlet g:filetype_bas - call delete('Xfile.hook') - filetype off -endfunc + " FreeBASIC -func Test_tf_file() - filetype on + call writefile(["/' FreeBASIC multiline comment '/"], 'Xfile.bas') + split Xfile.bas + call assert_equal('freebasic', &filetype) + bwipe! - call writefile([';;; TF MUD client is super duper cool'], 'Xfile.tf') - split Xfile.tf - call assert_equal('tf', &filetype) + call writefile(['#define TESTING'], 'Xfile.bas') + split Xfile.bas + call assert_equal('freebasic', &filetype) bwipe! - call writefile(['provider "azurerm" {'], 'Xfile.tf') - split Xfile.tf - call assert_equal('terraform', &filetype) + call writefile(['option byval'], 'Xfile.bas') + split Xfile.bas + call assert_equal('freebasic', &filetype) bwipe! - call delete('Xfile.tf') - filetype off -endfunc + call writefile(['extern "C"'], 'Xfile.bas') + split Xfile.bas + call assert_equal('freebasic', &filetype) + bwipe! + " QB64 -func Test_ts_file() - filetype on + call writefile(['$LET TESTING = 1'], 'Xfile.bas') + split Xfile.bas + call assert_equal('qb64', &filetype) + bwipe! - call writefile([''], 'Xfile.ts') - split Xfile.ts - call assert_equal('xml', &filetype) + call writefile(['OPTION _EXPLICIT'], 'Xfile.bas') + split Xfile.bas + call assert_equal('qb64', &filetype) bwipe! - call writefile(['// looks like Typescript'], 'Xfile.ts') - split Xfile.ts - call assert_equal('typescript', &filetype) + " Visual Basic + + call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas') + split Xfile.bas + call assert_equal('vb', &filetype) bwipe! - call delete('Xfile.ts') + call delete('Xfile.bas') filetype off endfunc -func Test_ttl_file() +func Test_dep3patch_file() filetype on - call writefile(['@base .'], 'Xfile.ttl') - split Xfile.ttl - call assert_equal('turtle', &filetype) - bwipe! + call assert_true(mkdir('debian/patches', 'p')) - call writefile(['looks like Tera Term Language'], 'Xfile.ttl') - split Xfile.ttl - call assert_equal('teraterm', &filetype) + " series files are not patches + call writefile(['Description: some awesome patch'], 'debian/patches/series') + split debian/patches/series + call assert_notequal('dep3patch', &filetype) bwipe! - call delete('Xfile.ttl') - filetype off -endfunc + " diff/patch files without the right headers should still show up as ft=diff + call writefile([], 'debian/patches/foo.diff') + split debian/patches/foo.diff + call assert_equal('diff', &filetype) + bwipe! -func Test_pp_file() - filetype on + " Files with the right headers are detected as dep3patch, even if they don't + " have a diff/patch extension + call writefile(['Subject: dep3patches'], 'debian/patches/bar') + split debian/patches/bar + call assert_equal('dep3patch', &filetype) + bwipe! - call writefile(['looks like puppet'], 'Xfile.pp') - split Xfile.pp - call assert_equal('puppet', &filetype) + " Files in sub-directories are detected + call assert_true(mkdir('debian/patches/s390x', 'p')) + call writefile(['Subject: dep3patches'], 'debian/patches/s390x/bar') + split debian/patches/s390x/bar + call assert_equal('dep3patch', &filetype) bwipe! - let g:filetype_pp = 'pascal' - split Xfile.pp - call assert_equal('pascal', &filetype) + " The detection stops when seeing the "header end" marker + call writefile(['---', 'Origin: the cloud'], 'debian/patches/baz') + split debian/patches/baz + call assert_notequal('dep3patch', &filetype) bwipe! - unlet g:filetype_pp - " Test dist#ft#FTpp() - call writefile(['{ pascal comment'], 'Xfile.pp') - split Xfile.pp - call assert_equal('pascal', &filetype) + call delete('debian', 'rf') +endfunc + +func Test_dsl_file() + filetype on + + call writefile([' '], 'Xfile.m') - split Xfile.m - call assert_equal('objc', &filetype) + call writefile(['FoamFile {', ' object something;'], '0.orig/Xfile') + split 0.orig/Xfile + call assert_equal('foam', &filetype) bwipe! - call writefile(['#define FORTY_TWO'], 'Xfile.m') - split Xfile.m - call assert_equal('objc', &filetype) - bwipe! + call delete('0', 'rf') + call delete('0.orig', 'rf') + call delete('Xfile1Dict') + call delete('Xfile1Dict.something') + call delete('XfileProperties') + call delete('XfileProperties.something') + filetype off +endfunc - " Octave +func Test_frm_file() + filetype on - call writefile(['# Octave line comment'], 'Xfile.m') - split Xfile.m - call assert_equal('octave', &filetype) + call writefile(['looks like FORM'], 'Xfile.frm') + split Xfile.frm + call assert_equal('form', &filetype) bwipe! - call writefile(['%!test "Octave test"'], 'Xfile.m') - split Xfile.m - call assert_equal('octave', &filetype) - bwipe! + " Test dist#ft#FTfrm() - call writefile(['unwind_protect'], 'Xfile.m') - split Xfile.m - call assert_equal('octave', &filetype) + let g:filetype_frm = 'form' + split Xfile.frm + call assert_equal('form', &filetype) bwipe! + unlet g:filetype_frm - call writefile(['try; 42; end_try_catch'], 'Xfile.m') - split Xfile.m - call assert_equal('octave', &filetype) + " Visual Basic + + call writefile(['Begin VB.Form Form1'], 'Xfile.frm') + split Xfile.frm + call assert_equal('vb', &filetype) bwipe! - " Mathematica + call delete('Xfile.frm') + filetype off +endfunc - call writefile(['(* Mathematica comment'], 'Xfile.m') - split Xfile.m - call assert_equal('mma', &filetype) - bwipe! - - " MATLAB - - call writefile(['% MATLAB line comment'], 'Xfile.m') - split Xfile.m - call assert_equal('matlab', &filetype) - bwipe! - - " Murphi - - call writefile(['-- Murphi comment'], 'Xfile.m') - split Xfile.m - call assert_equal('murphi', &filetype) - bwipe! - - call writefile(['/* Murphi block comment */', 'Type'], 'Xfile.m') - split Xfile.m - call assert_equal('murphi', &filetype) - bwipe! - - call writefile(['Type'], 'Xfile.m') - split Xfile.m - call assert_equal('murphi', &filetype) - bwipe! - - call delete('Xfile.m') - filetype off -endfunc - -func Test_xpm_file() - filetype on - - call writefile(['this is XPM2'], 'file.xpm') - split file.xpm - call assert_equal('xpm2', &filetype) - bwipe! - - call delete('file.xpm') - filetype off -endfunc - -func Test_fs_file() - filetype on - - call writefile(['looks like F#'], 'Xfile.fs') - split Xfile.fs - call assert_equal('fsharp', &filetype) +func Test_fs_file() + filetype on + + call writefile(['looks like F#'], 'Xfile.fs') + split Xfile.fs + call assert_equal('fsharp', &filetype) bwipe! let g:filetype_fs = 'forth' @@ -1073,68 +1050,6 @@ func Test_fs_file() filetype off endfunc -func Test_dep3patch_file() - filetype on - - call assert_true(mkdir('debian/patches', 'p')) - - " series files are not patches - call writefile(['Description: some awesome patch'], 'debian/patches/series') - split debian/patches/series - call assert_notequal('dep3patch', &filetype) - bwipe! - - " diff/patch files without the right headers should still show up as ft=diff - call writefile([], 'debian/patches/foo.diff') - split debian/patches/foo.diff - call assert_equal('diff', &filetype) - bwipe! - - " Files with the right headers are detected as dep3patch, even if they don't - " have a diff/patch extension - call writefile(['Subject: dep3patches'], 'debian/patches/bar') - split debian/patches/bar - call assert_equal('dep3patch', &filetype) - bwipe! - - " Files in sub-directories are detected - call assert_true(mkdir('debian/patches/s390x', 'p')) - call writefile(['Subject: dep3patches'], 'debian/patches/s390x/bar') - split debian/patches/s390x/bar - call assert_equal('dep3patch', &filetype) - bwipe! - - " The detection stops when seeing the "header end" marker - call writefile(['---', 'Origin: the cloud'], 'debian/patches/baz') - split debian/patches/baz - call assert_notequal('dep3patch', &filetype) - bwipe! - - call delete('debian', 'rf') -endfunc - -func Test_patch_file() - filetype on - - call writefile([], 'Xfile.patch') - split Xfile.patch - call assert_equal('diff', &filetype) - bwipe! - - call writefile(['From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch') - split Xfile.patch - call assert_equal('gitsendemail', &filetype) - bwipe! - - call writefile(['From 0000000000000000000000000000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch') - split Xfile.patch - call assert_equal('gitsendemail', &filetype) - bwipe! - - call delete('Xfile.patch') - filetype off -endfunc - func Test_git_file() filetype on @@ -1164,145 +1079,188 @@ func Test_git_file() filetype off endfunc -func Test_foam_file() +func Test_hook_file() filetype on - call assert_true(mkdir('0', 'p')) - call assert_true(mkdir('0.orig', 'p')) - call writefile(['FoamFile {', ' object something;'], 'Xfile1Dict') - split Xfile1Dict - call assert_equal('foam', &filetype) + call writefile(['[Trigger]', 'this is pacman config'], 'Xfile.hook') + split Xfile.hook + call assert_equal('dosini', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], 'Xfile1Dict.something') - split Xfile1Dict.something - call assert_equal('foam', &filetype) + call writefile(['not pacman'], 'Xfile.hook') + split Xfile.hook + call assert_notequal('dosini', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], 'XfileProperties') - split XfileProperties - call assert_equal('foam', &filetype) + call delete('Xfile.hook') + filetype off +endfunc + +func Test_m_file() + filetype on + + call writefile(['looks like Matlab'], 'Xfile.m') + split Xfile.m + call assert_equal('matlab', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], 'XfileProperties.something') - split XfileProperties.something - call assert_equal('foam', &filetype) + let g:filetype_m = 'octave' + split Xfile.m + call assert_equal('octave', &filetype) bwipe! + unlet g:filetype_m - call writefile(['FoamFile {', ' object something;'], 'XfileProperties') - split XfileProperties - call assert_equal('foam', &filetype) + " Test dist#ft#FTm() + + " Objective-C + + call writefile(['// Objective-C line comment'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], 'XfileProperties.something') - split XfileProperties.something - call assert_equal('foam', &filetype) + call writefile(['/* Objective-C block comment */'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], '0/Xfile') - split 0/Xfile - call assert_equal('foam', &filetype) + call writefile(['#import "test.m"'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) bwipe! - call writefile(['FoamFile {', ' object something;'], '0.orig/Xfile') - split 0.orig/Xfile - call assert_equal('foam', &filetype) + call writefile(['#include '], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) bwipe! - call delete('0', 'rf') - call delete('0.orig', 'rf') - call delete('Xfile1Dict') - call delete('Xfile1Dict.something') - call delete('XfileProperties') - call delete('XfileProperties.something') - filetype off -endfunc + call writefile(['#define FORTY_TWO'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) + bwipe! -func Test_bas_file() - filetype on + " Octave - call writefile(['looks like BASIC'], 'Xfile.bas') - split Xfile.bas - call assert_equal('basic', &filetype) + call writefile(['# Octave line comment'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) bwipe! - " Test dist#ft#FTbas() - - let g:filetype_bas = 'freebasic' - split Xfile.bas - call assert_equal('freebasic', &filetype) + call writefile(['%!test "Octave test"'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) bwipe! - unlet g:filetype_bas - " FreeBASIC + call writefile(['unwind_protect'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! - call writefile(["/' FreeBASIC multiline comment '/"], 'Xfile.bas') - split Xfile.bas - call assert_equal('freebasic', &filetype) + call writefile(['try; 42; end_try_catch'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) bwipe! - call writefile(['#define TESTING'], 'Xfile.bas') - split Xfile.bas - call assert_equal('freebasic', &filetype) + " Mathematica + + call writefile(['(* Mathematica comment'], 'Xfile.m') + split Xfile.m + call assert_equal('mma', &filetype) bwipe! - call writefile(['option byval'], 'Xfile.bas') - split Xfile.bas - call assert_equal('freebasic', &filetype) + " MATLAB + + call writefile(['% MATLAB line comment'], 'Xfile.m') + split Xfile.m + call assert_equal('matlab', &filetype) bwipe! - call writefile(['extern "C"'], 'Xfile.bas') - split Xfile.bas - call assert_equal('freebasic', &filetype) + " Murphi + + call writefile(['-- Murphi comment'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) bwipe! - " QB64 + call writefile(['/* Murphi block comment */', 'Type'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) + bwipe! - call writefile(['$LET TESTING = 1'], 'Xfile.bas') - split Xfile.bas - call assert_equal('qb64', &filetype) + call writefile(['Type'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) bwipe! - call writefile(['OPTION _EXPLICIT'], 'Xfile.bas') - split Xfile.bas - call assert_equal('qb64', &filetype) + call delete('Xfile.m') + filetype off +endfunc + +func Test_patch_file() + filetype on + + call writefile([], 'Xfile.patch') + split Xfile.patch + call assert_equal('diff', &filetype) bwipe! - " Visual Basic + call writefile(['From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch') + split Xfile.patch + call assert_equal('gitsendemail', &filetype) + bwipe! - call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas') - split Xfile.bas - call assert_equal('vb', &filetype) + call writefile(['From 0000000000000000000000000000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001'], 'Xfile.patch') + split Xfile.patch + call assert_equal('gitsendemail', &filetype) bwipe! - call delete('Xfile.bas') + call delete('Xfile.patch') filetype off endfunc -func Test_frm_file() +func Test_perl_file() filetype on - call writefile(['looks like FORM'], 'Xfile.frm') - split Xfile.frm - call assert_equal('form', &filetype) - bwipe! + " only tests one case, should do more + let lines =<< trim END - " Test dist#ft#FTfrm() + use a + END + call writefile(lines, "Xfile.t") + split Xfile.t + call assert_equal('perl', &filetype) + bwipe - let g:filetype_frm = 'form' - split Xfile.frm - call assert_equal('form', &filetype) + call delete('Xfile.t') + filetype off +endfunc + +func Test_pp_file() + filetype on + + call writefile(['looks like puppet'], 'Xfile.pp') + split Xfile.pp + call assert_equal('puppet', &filetype) bwipe! - unlet g:filetype_frm - " Visual Basic + let g:filetype_pp = 'pascal' + split Xfile.pp + call assert_equal('pascal', &filetype) + bwipe! + unlet g:filetype_pp - call writefile(['Begin VB.Form Form1'], 'Xfile.frm') - split Xfile.frm - call assert_equal('vb', &filetype) + " Test dist#ft#FTpp() + call writefile(['{ pascal comment'], 'Xfile.pp') + split Xfile.pp + call assert_equal('pascal', &filetype) bwipe! - call delete('Xfile.frm') + call writefile(['procedure pascal'], 'Xfile.pp') + split Xfile.pp + call assert_equal('pascal', &filetype) + bwipe! + + call delete('Xfile.pp') filetype off endfunc @@ -1324,5 +1282,68 @@ func Test_tex_file() filetype off endfunc +func Test_tf_file() + filetype on + + call writefile([';;; TF MUD client is super duper cool'], 'Xfile.tf') + split Xfile.tf + call assert_equal('tf', &filetype) + bwipe! + + call writefile(['provider "azurerm" {'], 'Xfile.tf') + split Xfile.tf + call assert_equal('terraform', &filetype) + bwipe! + + call delete('Xfile.tf') + filetype off +endfunc + +func Test_ts_file() + filetype on + + call writefile([''], 'Xfile.ts') + split Xfile.ts + call assert_equal('xml', &filetype) + bwipe! + + call writefile(['// looks like Typescript'], 'Xfile.ts') + split Xfile.ts + call assert_equal('typescript', &filetype) + bwipe! + + call delete('Xfile.ts') + filetype off +endfunc + +func Test_ttl_file() + filetype on + + call writefile(['@base .'], 'Xfile.ttl') + split Xfile.ttl + call assert_equal('turtle', &filetype) + bwipe! + + call writefile(['looks like Tera Term Language'], 'Xfile.ttl') + split Xfile.ttl + call assert_equal('teraterm', &filetype) + bwipe! + + call delete('Xfile.ttl') + filetype off +endfunc + +func Test_xpm_file() + filetype on + + call writefile(['this is XPM2'], 'file.xpm') + split file.xpm + call assert_equal('xpm2', &filetype) + bwipe! + + call delete('file.xpm') + filetype off +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 3d72ecafc..3ea8fe24c 100644 --- a/src/version.c +++ b/src/version.c @@ -746,6 +746,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 4306, /**/ 4305, /**/ -- cgit v1.2.1