Skip to content

Commit

Permalink
Locale.Message: Refactor test
Browse files Browse the repository at this point in the history
* Check if ja_JP.UTF-8 is available before running each test
  • Loading branch information
ujihisa committed Jun 11, 2018
1 parent 0860074 commit ffc5fa5
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions test/Locale/Message.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ let s:text_path = 'test/Locale/MessageText/%s.txt'
Describe Locale.Message
Before all
let M = vital#vital#new().import('Locale.Message')
try
language message ja_JP.UTF-8
let ja_available = 1
catch /^Vim\%((\a\+)\)\=:E197/
let ja_available = 0
endtry
End

Before each
Expand All @@ -13,17 +19,17 @@ Describe Locale.Message

Describe .get_lang()
It returns current language of message
try
if ja_available
language message ja_JP.UTF-8
Assert Equals(M.get_lang(), 'ja')
catch /^Vim\%((\a\+)\)\=:E197/
else
try
language message en_US.UTF-8
Assert Equals(M.get_lang(), 'en')
catch /^Vim\%((\a\+)\)\=:E197/
Skip Need ja_JP.UTF-8 or en_US.UTF-8 in your system locale
endtry
endtry
endif
End
It returns 'en' if current language is 'C'
language message C
Expand All @@ -41,17 +47,17 @@ Describe Locale.Message

Describe .get()
Before each
try
if ja_available
language message ja_JP.UTF-8
let self.m = M.new(s:text_path)
catch /^Vim\%((\a\+)\)\=:E197/
else
try
language message en_US.UTF-8
let self.m = M.new(s:text_path)
catch /^Vim\%((\a\+)\)\=:E197/
Skip Need ja_JP.UTF-8 or en_US.UTF-8 in your system locale
endtry
endtry
endif
End
It returns translated text if it exists
if M.get_lang() == 'ja'
Expand All @@ -67,17 +73,17 @@ Describe Locale.Message

Describe ._()
Before each
try
if ja_available
language message ja_JP.UTF-8
let self.m = M.new(s:text_path)
catch /^Vim\%((\a\+)\)\=:E197/
else
try
language message en_US.UTF-8
let self.m = M.new(s:text_path)
catch /^Vim\%((\a\+)\)\=:E197/
Skip Need ja_JP.UTF-8 or en_US.UTF-8 in your system locale
endtry
endtry
endif
End
It can use like `get()`
if M.get_lang() == 'ja'
Expand Down

0 comments on commit ffc5fa5

Please sign in to comment.