Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitbfc5688

Browse files
committed
fix(editor-export): schema eadge case
1 parenteb76895 commitbfc5688

File tree

6 files changed

+51
-31
lines changed

6 files changed

+51
-31
lines changed

‎lib/helper/converter/editor_to_html/validator/editor_schema.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule Helper.Converter.EditorToHTML.Validator.EditorSchema do
4848

4949
defget("table")do
5050
[
51-
parent:%{"columnCount"=>[:number],"items"=>[:list]},
51+
parent:%{"columnCount"=>[:number,min:2],"items"=>[:list]},
5252
item:%{
5353
"text"=>[:string],
5454
"align"=>[enum:@valid_table_align],

‎lib/helper/validator/schema.ex‎

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,26 @@ defmodule Helper.Validator.Schema do
107107
# custom validate logic end
108108

109109
# main type
110-
defpmatch(field,value,:string,[])whenis_binary(value)do
111-
done(field,value)
112-
end
113-
114-
defpmatch(field,value,:number,[])whenis_integer(value)do
115-
done(field,value)
116-
end
117-
118-
defpmatch(field,value,:list,[])whenis_list(value)do
119-
done(field,value)
120-
end
121-
122-
defpmatch(field,value,:boolean,[])whenis_boolean(value)do
123-
done(field,value)
124-
end
125-
110+
defpmatch(field,value,:string,[])whenis_binary(value),do:done(field,value)
111+
defpmatch(field,value,:number,[])whenis_integer(value),do:done(field,value)
112+
defpmatch(field,value,:list,[])whenis_list(value),do:done(field,value)
113+
defpmatch(field,value,:boolean,[])whenis_boolean(value),do:done(field,value)
126114
# main type end
127115

128-
defpmatch(field,value,_type,[option])whenis_tuple(option)andnotis_nil(value)do
129-
{k,v}=option
130-
error(field,value,option:"#{to_string(k)}:#{to_string(v)}")
131-
end
116+
# judge option
117+
defpmatch(field,value,type,[option])whenis_tuple(option)do
118+
# 如果这里不判断的话会和下面的 match 冲突,是否有更好的写法?
119+
caseoption_valid?(option)do
120+
true->
121+
error(field,value,type)
132122

133-
defpmatch(field,value,_type,[_option])whennotis_nil(value)do
134-
error(field,value,:option)
123+
false->
124+
{k,v}=option
125+
error(field,value,option:"#{to_string(k)}:#{to_string(v)}")
126+
end
135127
end
136128

137-
defpmatch(field,value,type,_)do
138-
error(field,value,type)
139-
end
129+
defpmatch(field,value,type,_),do:error(field,value,type)
140130

141131
defpdone(field,value),do:{:ok,%{field:field,value:value}}
142132

@@ -155,4 +145,8 @@ defmodule Helper.Validator.Schema do
155145
defperror(field,value,schema)do
156146
{:error,%{field:field|>to_string,value:value,message:"should be:#{schema}"}}
157147
end
148+
149+
defpoption_valid?({:min,v})whenis_integer(v),do:true
150+
defpoption_valid?({:required,v})whenis_boolean(v),do:true
151+
defpoption_valid?(_),do:false
158152
end

‎test/helper/converter/editor_to_html_test/header_test.exs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do
127127
{:ok,editor_string}=Jason.encode(json)
128128
{:ok,converted}=Parser.to_html(editor_string)
129129

130-
IO.inspect(converted,label:"converted --")
131-
132130
assertUtils.str_occurence(converted,@eyebrow_class)==0
133131
assertUtils.str_occurence(converted,@footer_class)==1
134132
end

‎test/helper/converter/editor_to_html_test/list_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do
1212

1313
describe"[list block unit]"do
1414
defpset_items(mode,items)do
15-
editor_json=%{
15+
%{
1616
"time"=>1_567_250_876_713,
1717
"blocks"=>[
1818
%{

‎test/helper/converter/editor_to_html_test/table_test.exs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do
119119
},
120120
%{block:"table",field:"items",message:"should be: list",value:"bb"}
121121
]
122+
123+
editor_json=set_items(-2,"bb")
124+
{:ok,editor_string}=Jason.encode(editor_json)
125+
{:error,err_msg}=Parser.to_html(editor_string)
126+
127+
asserterr_msg==[
128+
%{block:"table",field:"columnCount",message:"min size: 2",value:-2},
129+
%{block:"table",field:"items",message:"should be: list",value:"bb"}
130+
]
122131
end
123132
end
124133
end

‎test/helper/validator/schema_test.exs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,32 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do
8383
{:error,error}=Schema.cast(schema,data)
8484
asserterror==[%{field:"text",message:"should be: number",value:nil}]
8585

86+
# IO.inspect(Schema.cast(schema, data), label: "schema result")
87+
# hello world
88+
end
89+
90+
@tag:wip
91+
test"number with wrong option"do
8692
schema=%{"text"=>[:number,required:true,min:"5"]}
8793
data=%{"text"=>1}
94+
8895
{:error,error}=Schema.cast(schema,data)
8996
asserterror==[%{field:"text",message:"unknow option: min: 5",value:1}]
9097

91-
# IO.inspect(Schema.cast(schema, data), label: "schema result")
92-
# hello world
98+
schema=%{"text"=>[:number,required:true,no_exsit_option:"xxx"]}
99+
data=%{"text"=>1}
100+
101+
{:error,error}=Schema.cast(schema,data)
102+
asserterror==[%{field:"text",message:"unknow option: no_exsit_option: xxx",value:1}]
103+
end
104+
105+
@tag:wip
106+
test"number with options edage case"do
107+
schema=%{"text"=>[:number,min:2]}
108+
data=%{"text"=>"aa"}
109+
110+
{:error,error}=Schema.cast(schema,data)
111+
asserterror==[%{field:"text",message:"should be: number",value:"aa"}]
93112
end
94113

95114
@tag:wip

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp