feat(format): select_wrap and join_wrap with when_long via Doc-IR
This commit is contained in:
@@ -647,3 +647,50 @@ func TestDMLCaseCollapseUsesLineWidth(t *testing.T) {
|
||||
t.Errorf("exceeds 30, should wrap:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectWrap(t *testing.T) {
|
||||
src := "select a, b, c from t"
|
||||
st := config.Default()
|
||||
if got := File(parser.Parse(src), st); !strings.Contains(got, "\n ,b") {
|
||||
t.Errorf("default select_wrap=always should list one per line:\n%s", got)
|
||||
}
|
||||
st.SelectWrap = config.WrapNever
|
||||
if got := File(parser.Parse(src), st); !strings.Contains(got, "SELECT a, b, c") {
|
||||
t.Errorf("never:\n%s", got)
|
||||
}
|
||||
st.SelectWrap = config.WrapWhenLong
|
||||
st.LineWidth = 120
|
||||
if got := File(parser.Parse(src), st); !strings.Contains(got, "SELECT a, b, c") {
|
||||
t.Errorf("when_long, short:\n%s", got)
|
||||
}
|
||||
st.LineWidth = 8
|
||||
if got := File(parser.Parse(src), st); !strings.Contains(got, "\n ,b") {
|
||||
t.Errorf("when_long, long:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinWrap(t *testing.T) {
|
||||
src := "select a from t join u on t.id = u.id and t.x = u.x"
|
||||
st := config.Default()
|
||||
base := File(parser.Parse(src), st)
|
||||
if !strings.Contains(base, "JOIN u ON t.id = u.id AND t.x = u.x") {
|
||||
t.Fatalf("default join_wrap=never should stay inline:\n%s", base)
|
||||
}
|
||||
st.JoinWrap = config.WrapAlways
|
||||
got := File(parser.Parse(src), st)
|
||||
if !strings.Contains(got, "JOIN u\n ON t.id = u.id\n AND t.x = u.x") {
|
||||
t.Errorf("always:\n%s", got)
|
||||
}
|
||||
if twice := File(parser.Parse(got), st); twice != got {
|
||||
t.Errorf("not idempotent:\n%s\n---\n%s", got, twice)
|
||||
}
|
||||
st.JoinWrap = config.WrapWhenLong
|
||||
st.LineWidth = 120
|
||||
if File(parser.Parse(src), st) != base {
|
||||
t.Errorf("when_long short should equal inline")
|
||||
}
|
||||
st.LineWidth = 20
|
||||
if File(parser.Parse(src), st) != got {
|
||||
t.Errorf("when_long long should equal always")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user