Skip to content

Commit

Permalink
vimscript/reverse-string: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 11, 2024
1 parent e9ceef0 commit ff31c11
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 2 deletions.
1 change: 1 addition & 0 deletions vimscript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
- [hello-world](./hello-world/README.md)
- [raindrops](./raindrops/README.md)
- [leap](./leap/README.md)
- [reverse-string](./reverse-string/README.md)
1 change: 1 addition & 0 deletions vimscript/reverse-string/.coverage_covimerage
Original file line number Diff line number Diff line change
@@ -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"}}
3 changes: 3 additions & 0 deletions vimscript/reverse-string/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
plugins = covimerage
data_file = .coverage_covimerage
17 changes: 17 additions & 0 deletions vimscript/reverse-string/.themisrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
" .themisrc

let g:repo_root = fnamemodify(expand('<sfile>'), ':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
10 changes: 9 additions & 1 deletion vimscript/reverse-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
24 changes: 24 additions & 0 deletions vimscript/reverse-string/coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.2" lines-covered="1" lines-valid="5" timestamp="1712851156142" version="4.5.4">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/vpayno/git_vpayno/exercism-workspace/vimscript/reverse-string</source>
</sources>
<packages>
<package branch-rate="0" complexity="0" line-rate="0.2" name=".">
<classes>
<class branch-rate="0" complexity="0" filename="reverse_string.vim" line-rate="0.2" name="reverse_string.vim">
<methods/>
<lines>
<line hits="1" number="9"/>
<line hits="0" number="10"/>
<line hits="0" number="12"/>
<line hits="0" number="13"/>
<line hits="0" number="16"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
47 changes: 47 additions & 0 deletions vimscript/reverse-string/profile.txt
Original file line number Diff line number Diff line change
@@ -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()

8 changes: 7 additions & 1 deletion vimscript/reverse-string/reverse_string.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
118 changes: 118 additions & 0 deletions vimscript/reverse-string/run-tests-vimscript.txt
Original file line number Diff line number Diff line change
@@ -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

===============================================================================

Expand Down
34 changes: 34 additions & 0 deletions vimscript/reverse-string/themis.vimspec
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ff31c11

Please sign in to comment.