Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozg committed Dec 30, 2023
1 parent ce43200 commit 271a27a
Show file tree
Hide file tree
Showing 6 changed files with 570 additions and 557 deletions.
16 changes: 12 additions & 4 deletions rime/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -558,23 +558,32 @@ end
-- IME
-- IME libs
local rime
local initialized
_G.initialized = nil

-- IME metatable
local mtIME = {
__index = {
-- help
toTraits = toTraits,
-- setup
setup = function(self, traits)
assert(_G.initialized == nil)
assert(traits)
self.api.setup(traits)
_G.initialized = true
end,
-- initialize
initialize = function(self, traits, fullcheck, on_message)
assert(self.initlized == nil)
local api = self.api
fullcheck = fullcheck or ffi.C.False
assert(traits)

if not initialized then
api.setup(traits)
if not _G.initialized then
self:setup(traits)
end

if not self.initlized then
on_message = on_message or function(context_object, session_id, message_type, message_value)
_ = context_object
local msg = string.format("message: [%d] [%s] %s\n",
Expand All @@ -590,7 +599,6 @@ local mtIME = {
if (self.api.start_maintenance(fullcheck)) then
api.join_maintenance_thread();
end
initialized = true
end
self.initlized = true
return self.initlized
Expand Down
301 changes: 151 additions & 150 deletions spec/base_spec.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
describe("basic test", function()
expose("an exposed test", function()
package.path = '?/init.lua;?.lua;'..package.path
local rime, traits, session, schema
local _ref = 0
local profile = require('profile')
local rime = require'rime'(assert(profile.traits.runtimePath))
local traits, _ref = nil, 0

setup(function()
if not rime then
local profile = require('profile')
rime = require'rime'(assert(profile.traits.runtimePath))
traits = rime:toTraits(
assert(profile.traits.dataPath),
assert(profile.traits.userPath),
assert(profile.traits.name),
assert(profile.traits.code_name),
assert(profile.traits.version)
)

assert(rime:initialize(traits, false, function() end))
end
traits = rime:toTraits(
assert(profile.traits.dataPath),
assert(profile.traits.userPath),
assert(profile.traits.name),
assert(profile.traits.code_name),
assert(profile.traits.version)
)

assert(rime:initialize(traits, false, function() end))
_ref = _ref + 1
end)

Expand All @@ -28,143 +25,147 @@ describe("basic test", function()
end
end)

it("session", function()
session = rime:SessionCreate()
rime:SessionCleanup()
assert(session:exist())
rime:SessionCleanup(true)
assert(session:exist()==false)
end)

it("schema", function()
session = rime:SessionCreate()
local _schema = session:Schema()
assert('string' == type(_schema))
if _schema ~= 'luna_pinyin' then
schema = 'luna_pinyin'
session:Schema(schema)
describe("basic test", function()
local session, schema

it("session", function()
session = rime:SessionCreate()
rime:SessionCleanup()
assert(session:exist())
rime:SessionCleanup(true)
assert(session:exist()==false)
end)

it("schema", function()
session = rime:SessionCreate()
local _schema = session:Schema()
assert('string' == type(_schema))
if _schema ~= 'luna_pinyin' then
schema = 'luna_pinyin'
session:Schema(schema)
schema = session:Schema()
end
end)

it("pinyin ascii_mode", function()
rime.utils.printInfo(session)
schema = session:Schema()
end
end)

it("pinyin ascii_mode", function()
rime.utils.printInfo(session)
schema = session:Schema()
print('current:',schema)
session:Schema(schema)
assert(schema==session:Schema())

rime:deploy_schema('luna_pinyin')
--change schema
local schema_list = rime:Schemas()
rime.utils.print_r(schema_list)

local schemaid = schema_list[#schema_list].id
assert(schemaid)
session:Schema(schema)
assert(schema==session:Schema())

local v = session:Option('ascii_mode')
session:Option('ascii_mode', not v)
assert(v~=session:Option('ascii_mode'))
session:Option('ascii_mode', v)

--disable ascii_mode
session:Option('ascii_mode', false)
local list = session:Candidates()
rime.utils.print_r(list,'list')

assert(session:simulate('abcd')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(type(list)=='table')
assert(#list > 0)
--rime.utils.print_r(list,'list of abcd')
assert(session:Select(1))
print(session:Commit())
rime.utils.printInfo(session)
end)
print('current:',schema)
session:Schema(schema)
assert(schema==session:Schema())

it("pinyin ime", function()
--disable ascii_mode
assert(session:Schema('luna_pinyin'))
session:Option('ascii_mode', false)
local list

rime.utils.printInfo(session)
assert(session:simulate('xiguanjiuhaole')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('burejinsiji')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "布热津斯基")
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('shurufangshizhuanhuanjian')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('chujiangkongwan')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(session:Select(1))
print(session:Commit())

local seq = "yitiaodahebolangkuanfengchuidaohuaxiangliang'an"
for i=1,#seq do
local keycode = seq:byte(i)
session:process(keycode)
--rime.utils.printInfo(session)
end
assert(session:Select(1))
print(session:Commit())
end)
rime:deploy_schema('luna_pinyin')
--change schema
local schema_list = rime:Schemas()
rime.utils.print_r(schema_list)

it("pinyin_fluency ime", function()
--disable ascii_mode
assert(session:Schema('luna_pinyin_fluency'))
session:Option('ascii_mode', false)

assert(session:simulate('xiguanjiuhaole')==true)
rime.utils.printInfo(session)
local list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())

local seq = "yitiaodahebolangkuanfengchuidaohuaxiangliang'an"
for i=1,#seq do
local keycode = seq:byte(i)
session:process(keycode)
end
rime.utils.printInfo(session)
assert(session:Select(1))
print(session:Commit())
end)
local schemaid = schema_list[#schema_list].id
assert(schemaid)
session:Schema(schema)
assert(schema==session:Schema())

local v = session:Option('ascii_mode')
session:Option('ascii_mode', not v)
assert(v~=session:Option('ascii_mode'))
session:Option('ascii_mode', v)

--disable ascii_mode
session:Option('ascii_mode', false)
local list = session:Candidates()
rime.utils.print_r(list,'list')

assert(session:simulate('abcd')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(type(list)=='table')
assert(#list > 0)
--rime.utils.print_r(list,'list of abcd')
assert(session:Select(1))
print(session:Commit())
rime.utils.printInfo(session)
end)

it("pinyin ime", function()
--disable ascii_mode
assert(session:Schema('luna_pinyin'))
session:Option('ascii_mode', false)
local list

rime.utils.printInfo(session)
assert(session:simulate('xiguanjiuhaole')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('burejinsiji')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "布热津斯基")
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('shurufangshizhuanhuanjian')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(session:Select(1))
print(session:Commit())

assert(session:simulate('chujiangkongwan')==true)
rime.utils.printInfo(session)
list = session:Candidates()
assert(session:Select(1))
print(session:Commit())

local seq = "yitiaodahebolangkuanfengchuidaohuaxiangliang'an"
for i=1,#seq do
local keycode = seq:byte(i)
session:process(keycode)
--rime.utils.printInfo(session)
end
assert(session:Select(1))
print(session:Commit())
end)

it("pinyin_fluency ime", function()
--disable ascii_mode
assert(session:Schema('luna_pinyin_fluency'))
session:Option('ascii_mode', false)

assert(session:simulate('xiguanjiuhaole')==true)
rime.utils.printInfo(session)
local list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())

local seq = "yitiaodahebolangkuanfengchuidaohuaxiangliang'an"
for i=1,#seq do
local keycode = seq:byte(i)
session:process(keycode)
end
rime.utils.printInfo(session)
assert(session:Select(1))
print(session:Commit())
end)

it("double_pinyin ime", function()
--disable ascii_mode
assert(session:Schema('double_pinyin'))
session:Option('ascii_mode', false)

assert(session:simulate('duguqqbl')==true)
rime.utils.printInfo(session)
local list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())
end)

it("double_pinyin ime", function()
--disable ascii_mode
assert(session:Schema('double_pinyin'))
session:Option('ascii_mode', false)

assert(session:simulate('duguqqbl')==true)
rime.utils.printInfo(session)
local list = session:Candidates()
assert(#list > 0)
--rime.utils.print_r(list, "习惯就好了")
assert(session:Select(1))
print(session:Commit())
end)

end)
Loading

0 comments on commit 271a27a

Please sign in to comment.