Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vimscript reverse #356

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 additions & 0 deletions vimscript/reverse-string/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"BNAndras"
],
"files": {
"solution": [
"reverse_string.vim"
],
"test": [
"reverse_string.vader"
],
"example": [
".meta/example.vim"
]
},
"blurb": "Reverse a given string.",
"source": "Introductory challenge to reverse an input string",
"source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb"
}
1 change: 1 addition & 0 deletions vimscript/reverse-string/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"vimscript","exercise":"reverse-string","id":"f700f10d947c4dd6b81af8629b046dad","url":"https://exercism.org/tracks/vimscript/exercises/reverse-string","handle":"vpayno","is_requester":true,"auto_approve":false}
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
52 changes: 52 additions & 0 deletions vimscript/reverse-string/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Help

## Running the tests

Open your solution:

```bash
$ vim <exercise>.vim
```

Source the current file to make its global functions available to Vim:

```
:source %
```

Run the tests:

```
:Vader <exercise>.vader
```

Replace `<exercise>` with your exercise's name.

## Submitting your solution

You can submit your solution using the `exercism submit reverse_string.vim` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Vim script track's documentation](https://exercism.org/docs/tracks/vimscript)
- The [Vim script track's programming category on the forum](https://forum.exercism.org/c/programming/vimscript)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

To get help if you're having trouble, you can use one of the following resources:

- [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com)
- [IBM DeveloperWorks: Scripting the Vim
editor](http://www.ibm.com/developerworks/views/linux/libraryview.jsp?sort_order=asc&sort_by=Title&search_by=scripting+the+vim+editor)
- [/r/vimscript](https://www.reddit.com/r/vimscript) is the Vimscript subreddit.
- [StackOverflow](http://stackoverflow.com/) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
38 changes: 38 additions & 0 deletions vimscript/reverse-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Reverse String

Welcome to Reverse String on Exercism's Vim script Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Introduction

Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.

For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.

## Instructions

Your task is to reverse a given string.

Some examples:

- Turn `"stressed"` into `"desserts"`.
- Turn `"strops"` into `"sports"`.
- Turn `"racecar"` into `"racecar"`.

## Source

### Created by

- @BNAndras

### 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

### 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()

30 changes: 30 additions & 0 deletions vimscript/reverse-string/reverse_string.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Execute (an empty string):
let g:value = ""
let g:expected = ""
AssertEqual g:expected, Reverse(g:value)

Execute (a word):
let g:value = "robot"
let g:expected = "tobor"
AssertEqual g:expected, Reverse(g:value)

Execute (a capitalized word):
let g:value = "Ramen"
let g:expected = "nemaR"
AssertEqual g:expected, Reverse(g:value)

Execute (a sentence with punctuation):
let g:value = "I'm hungry!"
let g:expected = "!yrgnuh m'I"
AssertEqual g:expected, Reverse(g:value)

Execute (a palindrome):
let g:value = "racecar"
let g:expected = "racecar"
AssertEqual g:expected, Reverse(g:value)

Execute (an even-sized word):
let g:value = "drawer"
let g:expected = "reward"
AssertEqual g:expected, Reverse(g:value)
17 changes: 17 additions & 0 deletions vimscript/reverse-string/reverse_string.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"
" Reverses the passed test
"
" Examples:
"
" :echo Reverse('Exercism')
" msicrexE
"
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
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
Loading
Loading