diff --git a/vimscript/README.md b/vimscript/README.md index fa6d81c0..3c7eb72e 100644 --- a/vimscript/README.md +++ b/vimscript/README.md @@ -17,3 +17,4 @@ - [hello-world](./hello-world/README.md) - [raindrops](./raindrops/README.md) - [leap](./leap/README.md) +- [reverse-string](./reverse-string/README.md) diff --git a/vimscript/reverse-string/.coverage_covimerage b/vimscript/reverse-string/.coverage_covimerage new file mode 100644 index 00000000..f4aec830 --- /dev/null +++ b/vimscript/reverse-string/.coverage_covimerage @@ -0,0 +1 @@ +!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string/reverse_string.vim":[9]},"file_tracers":{"/home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string/reverse_string.vim":"covimerage.CoveragePlugin"}} \ No newline at end of file diff --git a/vimscript/reverse-string/.coveragerc b/vimscript/reverse-string/.coveragerc new file mode 100644 index 00000000..8cddf91c --- /dev/null +++ b/vimscript/reverse-string/.coveragerc @@ -0,0 +1,3 @@ +[run] +plugins = covimerage +data_file = .coverage_covimerage diff --git a/vimscript/reverse-string/.themisrc b/vimscript/reverse-string/.themisrc new file mode 100644 index 00000000..5c43c80e --- /dev/null +++ b/vimscript/reverse-string/.themisrc @@ -0,0 +1,17 @@ +" .themisrc + +let g:repo_root = fnamemodify(expand(''), ':h:h') + +call themis#option('exclude', g:repo_root . '/*.md') +call themis#option('exclude', g:repo_root . '/*.vader') +call themis#option('exclude', g:repo_root . '/*.txt') +call themis#helper('command').with(themis#helper('assert')) + +if $PROFILE_LOG !=# '' + execute 'profile' 'start' $PROFILE_LOG + execute 'profile!' 'file' g:repo_root . '/*.vim' +endif + +call themis#option('runtimepath', expand(g:repo_root)) + +" vim:ft=vim diff --git a/vimscript/reverse-string/README.md b/vimscript/reverse-string/README.md index a731484e..5678bfe7 100644 --- a/vimscript/reverse-string/README.md +++ b/vimscript/reverse-string/README.md @@ -27,4 +27,12 @@ Some examples: ### Based on -Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb \ No newline at end of file +Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb + +### My Solution + +- [my solution](./reverse_string.vim) +- [vader tests](./reverse_string.vader) +- [themis tests](./themis.vimspec) +- [themis profile](./profile.txt) +- [run-tests output](./run-tests-vimscript.txt) diff --git a/vimscript/reverse-string/coverage.xml b/vimscript/reverse-string/coverage.xml new file mode 100644 index 00000000..a969579f --- /dev/null +++ b/vimscript/reverse-string/coverage.xml @@ -0,0 +1,24 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string + + + + + + + + + + + + + + + + + + diff --git a/vimscript/reverse-string/profile.txt b/vimscript/reverse-string/profile.txt new file mode 100644 index 00000000..8ead95ad --- /dev/null +++ b/vimscript/reverse-string/profile.txt @@ -0,0 +1,47 @@ +SCRIPT /home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string/reverse_string.vim +Sourced 1 time +Total time: 0.000013581 + Self time: 0.000013581 + +count total (s) self (s) + " + " Reverses the passed test + " + " Examples: + " + " :echo Reverse('Exercism') + " msicrexE + " + 1 0.000002889 function! Reverse(text) abort + let l:rtext = '' + + for s:item in split(a:text, '\zs') + let l:rtext = s:item . l:rtext + endfor + + return l:rtext + endfunction + +FUNCTION Reverse() + Defined: ~/git_vpayno/exercism-workspace/vimscript/reverse-string/reverse_string.vim:9 +Called 6 times +Total time: 0.000140630 + Self time: 0.000140630 + +count total (s) self (s) + 6 0.000026721 let l:rtext = '' + + 40 0.000046056 for s:item in split(a:text, '\zs') + 34 0.000035614 let l:rtext = s:item . l:rtext + 40 0.000014829 endfor + + 6 0.000004430 return l:rtext + +FUNCTIONS SORTED ON TOTAL TIME +count total (s) self (s) function + 6 0.000140630 Reverse() + +FUNCTIONS SORTED ON SELF TIME +count total (s) self (s) function + 6 0.000140630 Reverse() + diff --git a/vimscript/reverse-string/reverse_string.vim b/vimscript/reverse-string/reverse_string.vim index 0bc22e15..66353ddc 100644 --- a/vimscript/reverse-string/reverse_string.vim +++ b/vimscript/reverse-string/reverse_string.vim @@ -7,5 +7,11 @@ " msicrexE " function! Reverse(text) abort - " your code goes here + let l:rtext = '' + + for s:item in split(a:text, '\zs') + let l:rtext = s:item . l:rtext + endfor + + return l:rtext endfunction diff --git a/vimscript/reverse-string/run-tests-vimscript.txt b/vimscript/reverse-string/run-tests-vimscript.txt new file mode 100644 index 00000000..d08f4be0 --- /dev/null +++ b/vimscript/reverse-string/run-tests-vimscript.txt @@ -0,0 +1,118 @@ +Running automated test file(s): + + +=============================================================================== + +Running: vint --warning --verbose --enable-neovim . +vint DEBUG: checking: `reverse_string.vim` +vint DEBUG: severity: WARNING +vint DEBUG: disabled: ProhibitAbbreviationOption +vint DEBUG: enabled: ProhibitAutocmdWithNoGroup +vint DEBUG: enabled: ProhibitCommandRelyOnUser +vint DEBUG: enabled: ProhibitCommandWithUnintendedSideEffect +vint DEBUG: enabled: ProhibitEncodingOptionAfterScriptEncoding +vint DEBUG: enabled: ProhibitEqualTildeOperator +vint DEBUG: enabled: ProhibitImplicitScopeBuiltinVariable +vint DEBUG: disabled: ProhibitImplicitScopeVariable +vint DEBUG: enabled: ProhibitInvalidMapCall +vint DEBUG: enabled: ProhibitMissingScriptEncoding +vint DEBUG: enabled: ProhibitNoAbortFunction +vint DEBUG: enabled: ProhibitSetNoCompatible +vint DEBUG: enabled: ProhibitUnnecessaryDoubleQuote +vint DEBUG: disabled: ProhibitUnusedVariable +vint DEBUG: enabled: ProhibitUsingUndeclaredVariable + +real 0m0.302s +user 0m0.195s +sys 0m0.110s + +=============================================================================== + +Running: vim '+source *vim | Vader!*' ./*.vader && echo Success || echo Failure +Vim: Warning: Output is not to a terminal +[?1049h[?1h=[?2004h[?25l"./reverse_string.vader" 30L, 746B [?2004l[?1l>[?1049l[?25hVader note: cannot print to stderr reliably/directly. Please consider using Vim's -es/-Es option (mode=n). +VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 24 2024 13:08:58) +Included patches: 1-50 +Compiled by vpayno@penguin +Huge version with GTK2 GUI. Features included (+) or not (-): ++acl +cmdline_hist +ex_extra +jumplist +mouse_dec +perl/dyn -sodium +textobjects +wildmenu ++arabic +cmdline_info +extra_search +keymap -mouse_gpm +persistent_undo +sound +textprop +windows ++autocmd +comments -farsi +lambda -mouse_jsbterm +popupwin +spell +timers +writebackup ++autochdir +conceal +file_in_path +langmap +mouse_netterm +postscript +startuptime +title +X11 +-autoservername +cryptv +find_in_path +libcall +mouse_sgr +printer +statusline +toolbar +xattr ++balloon_eval +cscope +float +linebreak -mouse_sysmouse +profile -sun_workshop +user_commands -xfontset ++balloon_eval_term +cursorbind +folding +lispindent +mouse_urxvt -python +syntax +vartabs +xim ++browse +cursorshape -footer +listcmds +mouse_xterm +python3/dyn +tag_binary +vertsplit -xpm +++builtin_terms +dialog_con_gui +fork() +localmap +multi_byte +quickfix -tag_old_static +vim9script +xsmp_interact ++byte_offset +diff +gettext +lua/dyn +multi_lang +reltime -tag_any_white +viminfo +xterm_clipboard ++channel +digraphs -hangul_input +menu -mzscheme +rightleft +tcl/dyn +virtualedit -xterm_save ++cindent +dnd +iconv +mksession +netbeans_intg +ruby +termguicolors +visual ++clientserver -ebcdic +insert_expand +modify_fname +num64 +scrollbind +terminal +visualextra ++clipboard +emacs_tags +ipv6 +mouse +packages +signs +terminfo +vreplace ++cmdline_compl +eval +job +mouseshape +path_extra +smartindent +termresponse +wildignore + system vimrc file: "$VIM/vimrc" + user vimrc file: "$HOME/.vimrc" + 2nd user vimrc file: "~/.vim/vimrc" + user exrc file: "$HOME/.exrc" + system gvimrc file: "$VIM/gvimrc" + user gvimrc file: "$HOME/.gvimrc" +2nd user gvimrc file: "~/.vim/gvimrc" + defaults file: "$VIMRUNTIME/defaults.vim" + system menu file: "$VIMRUNTIME/menu.vim" + fall-back for $VIM: "/home/vpayno/.local/vim/usr/share/vim" + f-b for $VIMRUNTIME: "/home/vpayno/.local/vim/usr/share/vim/vim82" +Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 +Linking: gcc -Wl,-E -rdynamic -Wl,-export-dynamic -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz -lfontconfig -lfreetype -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lrt -ldl -L/home/vpayno/.local/activetcl-8.6/lib -ltclstub8.6 -ldl -lz -lpthread -lm -Wl,-rpath,/home/vpayno/.rbenv/versions/3.1.1/lib -L/home/vpayno/.rbenv/versions/3.1.1/lib -lruby -lm + +Starting Vader: 1 suite(s), 6 case(s) + Starting Vader: /home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string/reverse_string.vader + (1/6) [EXECUTE] an empty string + (2/6) [EXECUTE] a word + (3/6) [EXECUTE] a capitalized word + (4/6) [EXECUTE] a sentence with punctuation + (5/6) [EXECUTE] a palindrome + (6/6) [EXECUTE] an even-sized word + Success/Total: 6/6 +Success/Total: 6/6 (assertions: 6/6) +Elapsed time: 0.08 sec. +[?1049h[?1h=[?2004h[?2004l[?2004h[?2004l +[?2004l[?1l>[?1049l +real 0m0.609s +user 0m0.294s +sys 0m0.143s +Success + +=============================================================================== + +Running: themis ./themis.vimspec +1..1 +ok 1 - thesis tests test_reverse_string + +# tests 1 +# passes 1 + +real 0m0.026s +user 0m0.015s +sys 0m0.005s + +=============================================================================== + +Script line does not match function line, ignoring: " let l:rtext = ''" != "26721 let l:rtext = ''". +Could not find source for function: Reverse +Writing coverage file .coverage_covimerage. +Coverage.py warning: Plugin file tracers (covimerage.CoveragePlugin) aren't supported with PyTracer +Name Stmts Miss Cover +---------------------------------------- +reverse_string.vim 5 4 20% +Coverage.py warning: Plugin file tracers (covimerage.CoveragePlugin) aren't supported with PyTracer + +=============================================================================== + +Running: misspell . + +real 0m0.021s +user 0m0.022s +sys 0m0.009s + +=============================================================================== + diff --git a/vimscript/reverse-string/themis.vimspec b/vimscript/reverse-string/themis.vimspec new file mode 100644 index 00000000..d596a31c --- /dev/null +++ b/vimscript/reverse-string/themis.vimspec @@ -0,0 +1,34 @@ +" themis.vimspec + +let s:suite = themis#suite('thesis tests') +let s:assert = themis#helper('assert') + +source *.vim + +let g:test_cases = { + \ '': '', + \ 'robot': 'tobor', + \ 'Ramen': 'nemaR', + \ 'I''m hungry!': '!yrgnuh m''I', + \ 'racecar': 'racecar', + \ 'drawer': 'reward' + \ } + +" The function name(my_test_1) will be a test name. +function s:suite.test_reverse_string() + let l:forward = 0 + let l:backward = 0 + + for l:key in keys(g:test_cases) + let l:forward = l:key + let l:backward = g:test_cases[l:key] + + let l:got = Reverse(l:forward) + let l:want = l:backward + + " appending the number to the want/got values to make it easier to debug failures + call s:assert.equals(l:forward . ':' . l:want, l:forward . ':' . l:got) + endfor +endfunction + +" vim: ft=vim