|
1 | 1 | use insta::assert_snapshot; |
2 | 2 |
|
3 | 3 | fn printed_tree(sql: &str) -> String { |
| 4 | + let sql = sql.trim(); |
4 | 5 | let mut result = String::new(); |
5 | 6 | let mut parser = tree_sitter::Parser::new(); |
6 | 7 | let _ = parser.set_language(&pgt_treesitter_grammar::LANGUAGE.into()); |
7 | | - let tree = parser.parse(sql.trim(), None).expect("Unable to parse!"); |
| 8 | + let tree = parser.parse(sql, None).expect("Unable to parse!"); |
8 | 9 | pgt_test_utils::print_ts_tree(&tree.root_node(), sql, 0, &mut result); |
9 | 10 | result |
10 | 11 | } |
@@ -102,3 +103,96 @@ fn test_2() { |
102 | 103 | ; [54..55] ';' |
103 | 104 | "); |
104 | 105 | } |
| 106 | + |
| 107 | +#[test] |
| 108 | +fn test_3() { |
| 109 | + let sql = r#" |
| 110 | +select |
| 111 | + u.id, |
| 112 | + u.email, |
| 113 | + cs.user_settings, |
| 114 | + cs.client_id |
| 115 | +from |
| 116 | + auth.users u |
| 117 | + join public.client_settings cs |
| 118 | + on u.id = cs.user_id; |
| 119 | +
|
| 120 | +"#; |
| 121 | + |
| 122 | + assert_snapshot!(printed_tree(sql), @r" |
| 123 | + program [0..25] 'select u.id, u.email, cs.user_settings, cs.client_id from auth.users u join public.client_settings cs on u.id = cs.user_id;' |
| 124 | + statement [0..24] 'select u.id, u.email, cs.user_settings, cs.client_id from auth.users u join public.client_settings cs on u.id = cs.user_id' |
| 125 | + select [0..16] 'select u.id, u.email, cs.user_settings, cs.client_id' |
| 126 | + keyword_select [0..6] 'select' |
| 127 | + select_expression [4..16] 'u.id, u.email, cs.user_settings, cs.client_id' |
| 128 | + term [4..8] 'u.id' |
| 129 | + column_reference [4..8] 'u.id' |
| 130 | + table_identifier [4..5] 'u' |
| 131 | + . [5..6] '.' |
| 132 | + column_identifier [6..8] 'id' |
| 133 | + , [8..9] ',' |
| 134 | + term [4..11] 'u.email' |
| 135 | + column_reference [4..11] 'u.email' |
| 136 | + table_identifier [4..5] 'u' |
| 137 | + . [5..6] '.' |
| 138 | + column_identifier [6..11] 'email' |
| 139 | + , [11..12] ',' |
| 140 | + term [4..20] 'cs.user_settings' |
| 141 | + column_reference [4..20] 'cs.user_settings' |
| 142 | + table_identifier [4..6] 'cs' |
| 143 | + . [6..7] '.' |
| 144 | + column_identifier [7..20] 'user_settings' |
| 145 | + , [20..21] ',' |
| 146 | + term [4..16] 'cs.client_id' |
| 147 | + column_reference [4..16] 'cs.client_id' |
| 148 | + table_identifier [4..6] 'cs' |
| 149 | + . [6..7] '.' |
| 150 | + column_identifier [7..16] 'client_id' |
| 151 | + from [0..24] 'from auth.users u join public.client_settings cs on u.id = cs.user_id' |
| 152 | + keyword_from [0..4] 'from' |
| 153 | + relation [4..16] 'auth.users u' |
| 154 | + object_reference [4..14] 'auth.users' |
| 155 | + any_identifier [4..8] 'auth' |
| 156 | + . [8..9] '.' |
| 157 | + any_identifier [9..14] 'users' |
| 158 | + any_identifier [15..16] 'u' |
| 159 | + join [4..24] 'join public.client_settings cs on u.id = cs.user_id' |
| 160 | + keyword_join [4..8] 'join' |
| 161 | + relation [9..34] 'public.client_settings cs' |
| 162 | + object_reference [9..31] 'public.client_settings' |
| 163 | + any_identifier [9..15] 'public' |
| 164 | + . [15..16] '.' |
| 165 | + any_identifier [16..31] 'client_settings' |
| 166 | + any_identifier [32..34] 'cs' |
| 167 | + keyword_on [4..6] 'on' |
| 168 | + binary_expression [7..24] 'u.id = cs.user_id' |
| 169 | + column_reference [7..11] 'u.id' |
| 170 | + table_identifier [7..8] 'u' |
| 171 | + . [8..9] '.' |
| 172 | + column_identifier [9..11] 'id' |
| 173 | + = [12..13] '=' |
| 174 | + column_reference [14..24] 'cs.user_id' |
| 175 | + table_identifier [14..16] 'cs' |
| 176 | + . [16..17] '.' |
| 177 | + column_identifier [17..24] 'user_id' |
| 178 | + ; [24..25] ';' |
| 179 | + "); |
| 180 | +} |
| 181 | + |
| 182 | +#[test] |
| 183 | +fn test_4() { |
| 184 | + let sql = r#"select "auth".REPLACED_TOKEN"#; |
| 185 | + |
| 186 | + assert_snapshot!(printed_tree(sql), @r#" |
| 187 | + program [0..28] 'select "auth".REPLACED_TOKEN' |
| 188 | + statement [0..28] 'select "auth".REPLACED_TOKEN' |
| 189 | + select [0..28] 'select "auth".REPLACED_TOKEN' |
| 190 | + keyword_select [0..6] 'select' |
| 191 | + select_expression [7..28] '"auth".REPLACED_TOKEN' |
| 192 | + term [7..28] '"auth".REPLACED_TOKEN' |
| 193 | + object_reference [7..28] '"auth".REPLACED_TOKEN' |
| 194 | + any_identifier [7..13] '"auth"' |
| 195 | + . [13..14] '.' |
| 196 | + any_identifier [14..28] 'REPLACED_TOKEN' |
| 197 | + "#); |
| 198 | +} |
0 commit comments