Skip to content

Commit aaf0af6

Browse files
committed
sq fixes
1 parent 56fbdd7 commit aaf0af6

File tree

3 files changed

+334
-0
lines changed

3 files changed

+334
-0
lines changed

src/main/java/com/github/_1c_syntax/bsl/reader/common/context/AbstractReaderContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ protected AbstractReaderContext(HierarchicalStreamReader reader) {
132132
supportVariant = SupportVariant.NONE;
133133
realClass = String.class; // заглушка
134134
builder = ""; // заглушка
135+
name = ""; // заглушка
135136
}
136137

137138
protected AbstractReaderContext(Path currentPath, MDReader mdReader) {
@@ -143,6 +144,7 @@ protected AbstractReaderContext(Path currentPath, MDReader mdReader) {
143144
supportVariant = SupportVariant.NONE;
144145
realClass = String.class; // заглушка
145146
builder = ""; // заглушка
147+
name = ""; // заглушка
146148
}
147149

148150
/**
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.reader;
23+
24+
import com.github._1c_syntax.bsl.mdclasses.Configuration;
25+
import com.github._1c_syntax.bsl.mdclasses.ExternalReport;
26+
import com.github._1c_syntax.bsl.mdclasses.MDCReadSettings;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.ValueSource;
30+
31+
import java.nio.file.Paths;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
class MDOReaderTest {
36+
37+
@Test
38+
void testReadConfigurationWithValidPath() {
39+
var path = Paths.get("src/test/resources/ext/edt/ssl_3_1");
40+
var configuration = MDOReader.readConfiguration(path);
41+
42+
assertThat(configuration).isNotNull();
43+
assertThat(configuration).isInstanceOf(Configuration.class);
44+
}
45+
46+
@Test
47+
void testReadConfigurationWithSettings() {
48+
var path = Paths.get("src/test/resources/ext/edt/ssl_3_1");
49+
var settings = MDCReadSettings.DEFAULT;
50+
var configuration = MDOReader.readConfiguration(path, settings);
51+
52+
assertThat(configuration).isNotNull();
53+
assertThat(configuration).isInstanceOf(Configuration.class);
54+
}
55+
56+
@Test
57+
void testReadConfigurationWithNonExistentPath() {
58+
var path = Paths.get("src/test/resources/nonexistent");
59+
var configuration = MDOReader.readConfiguration(path);
60+
61+
assertThat(configuration).isNotNull();
62+
assertThat(configuration).isEqualTo(Configuration.EMPTY);
63+
}
64+
65+
@ParameterizedTest
66+
@ValueSource(strings = {
67+
"src/test/resources/ext/edt/ssl_3_1",
68+
"src/test/resources/ext/designer/ssl_3_1/src/cf"
69+
})
70+
void testReadConfigurationDifferentSources(String pathString) {
71+
var path = Paths.get(pathString);
72+
var configuration = MDOReader.readConfiguration(path);
73+
74+
assertThat(configuration).isNotNull();
75+
assertThat(configuration).isInstanceOf(Configuration.class);
76+
}
77+
78+
@Test
79+
void testReadWithNonExistentObject() {
80+
var path = Paths.get("src/test/resources/ext/edt/ssl_3_1");
81+
var result = MDOReader.read(path, "CommonModules.NonExistent");
82+
83+
// Should return null for non-existent object
84+
assertThat(result).isNull();
85+
}
86+
87+
@Test
88+
void testReadExternalSource() {
89+
var path = Paths.get("src/test/resources/ext/edt/external/ExternalDataProcessors/ТестоваяОбработка/ТестоваяОбработка.mdo");
90+
var externalSource = MDOReader.readExternalSource(path);
91+
92+
assertThat(externalSource).isNotNull();
93+
}
94+
95+
@Test
96+
void testReadExternalSourceWithSettings() {
97+
var path = Paths.get("src/test/resources/ext/edt/external/ExternalDataProcessors/ТестоваяОбработка/ТестоваяОбработка.mdo");
98+
var settings = MDCReadSettings.SKIP_SUPPORT;
99+
var externalSource = MDOReader.readExternalSource(path, settings);
100+
101+
assertThat(externalSource).isNotNull();
102+
}
103+
104+
@Test
105+
void testReadExternalSourceWithInvalidPath() {
106+
var path = Paths.get("src/test/resources/nonexistent.mdo");
107+
var externalSource = MDOReader.readExternalSource(path);
108+
109+
assertThat(externalSource).isNotNull();
110+
assertThat(externalSource).isEqualTo(ExternalReport.EMPTY);
111+
}
112+
113+
@Test
114+
void testReadConfigurationFromFile() {
115+
var path = Paths.get("src/test/resources/ext/edt/ssl_3_1/configuration/Configuration.mdo");
116+
var configuration = MDOReader.readConfiguration(path);
117+
118+
assertThat(configuration).isNotNull();
119+
assertThat(configuration).isInstanceOf(Configuration.class);
120+
}
121+
122+
@Test
123+
void testReadConfigurationFromDesignerFile() {
124+
var path = Paths.get("src/test/resources/ext/designer/ssl_3_1/src/Configuration/Configuration.xml");
125+
var configuration = MDOReader.readConfiguration(path);
126+
127+
assertThat(configuration).isNotNull();
128+
assertThat(configuration).isInstanceOf(Configuration.class);
129+
}
130+
131+
@Test
132+
void testReadConfigurationWithEmptyPath() {
133+
var path = Paths.get("");
134+
var configuration = MDOReader.readConfiguration(path);
135+
136+
assertThat(configuration).isNotNull();
137+
}
138+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
5+
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.reader.common;
23+
24+
import lombok.Builder;
25+
import lombok.Data;
26+
import lombok.Getter;
27+
import lombok.Singular;
28+
import org.junit.jupiter.api.Test;
29+
30+
import java.nio.file.Paths;
31+
import java.util.List;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
35+
36+
class TransformationUtilsTest {
37+
38+
@Test
39+
void testSetValueWithValidParameters() {
40+
var builder = TestClass.builder();
41+
TransformationUtils.setValue(builder, "name", "TestName");
42+
43+
var result = builder.build();
44+
assertThat(result.getName()).isEqualTo("TestName");
45+
}
46+
47+
@Test
48+
void testSetValueWithListParameter() {
49+
var builder = TestClassWithList.builder();
50+
TransformationUtils.setValue(builder, "items", List.of("item1", "item2"));
51+
52+
var result = builder.build();
53+
assertThat(result.getItems()).containsExactly("item1", "item2");
54+
}
55+
56+
@Test
57+
void testSetValueWithSingularParameter() {
58+
var builder = TestClassWithList.builder();
59+
TransformationUtils.setValue(builder, "item", "singleItem");
60+
61+
var result = builder.build();
62+
assertThat(result.getItems()).contains("singleItem");
63+
}
64+
65+
@Test
66+
void testInvokeWithValidMethod() {
67+
var mutableObject = new MutableTestClass();
68+
TransformationUtils.invoke(mutableObject, "reset");
69+
70+
assertThat(mutableObject.isReset()).isTrue();
71+
}
72+
73+
@Test
74+
void testInvokeWithNonExistentMethod() {
75+
var mutableObject = new MutableTestClass();
76+
// Should not throw, just log error
77+
TransformationUtils.invoke(mutableObject, "nonExistentMethod");
78+
79+
assertThat(mutableObject.isReset()).isFalse();
80+
}
81+
82+
@Test
83+
void testFieldType() {
84+
var builder = TestClass.builder();
85+
var type = TransformationUtils.fieldType(builder, "name");
86+
87+
assertThat(type).isNotNull();
88+
assertThat(type.getTypeName()).contains("String");
89+
}
90+
91+
@Test
92+
void testFieldTypeWithNonExistentField() {
93+
var builder = TestClass.builder();
94+
var type = TransformationUtils.fieldType(builder, "nonExistent");
95+
96+
assertThat(type).isNull();
97+
}
98+
99+
@Test
100+
void testBuilder() {
101+
var builder = TransformationUtils.builder(TestClass.class);
102+
103+
assertThat(builder).isNotNull();
104+
assertThat(builder).isInstanceOf(TestClass.TestClassBuilder.class);
105+
}
106+
107+
@Test
108+
void testBuilderWithClassWithoutBuilder() {
109+
assertThatThrownBy(() -> TransformationUtils.builder(String.class))
110+
.isInstanceOf(IllegalArgumentException.class)
111+
.hasMessageContaining("Incorrect class");
112+
}
113+
114+
@Test
115+
void testToBuilderWithClassWithoutToBuilder() {
116+
var simpleObject = new SimpleTestClass("test");
117+
var builder = TransformationUtils.toBuilder(simpleObject);
118+
119+
assertThat(builder).isNull();
120+
}
121+
122+
@Test
123+
void testBuildWithBuilder() {
124+
var builder = TestClass.builder().name("Test").value(100);
125+
var result = TransformationUtils.build(builder);
126+
127+
assertThat(result).isNotNull();
128+
assertThat(result).isInstanceOf(TestClass.class);
129+
assertThat(((TestClass) result).getName()).isEqualTo("Test");
130+
assertThat(((TestClass) result).getValue()).isEqualTo(100);
131+
}
132+
133+
@Test
134+
void testBuildWithBuilderAndPath() {
135+
var builder = TestClass.builder().name("Test").value(100);
136+
var path = Paths.get("test/path");
137+
var result = TransformationUtils.build(builder, path);
138+
139+
assertThat(result).isNotNull();
140+
assertThat(result).isInstanceOf(TestClass.class);
141+
}
142+
143+
@Test
144+
void testBuildWithInvalidBuilder() {
145+
var result = TransformationUtils.build("not a builder");
146+
147+
assertThat(result).isNull();
148+
}
149+
150+
@Test
151+
void testSetValueWithInvalidMethodName() {
152+
var builder = TestClass.builder();
153+
// Should not throw, just log error
154+
TransformationUtils.setValue(builder, "nonExistentMethod", "value");
155+
156+
var result = builder.build();
157+
assertThat(result).isNotNull();
158+
}
159+
160+
@Test
161+
void testFieldTypeWithListParameter() {
162+
var builder = TestClassWithList.builder();
163+
var type = TransformationUtils.fieldType(builder, "items");
164+
165+
assertThat(type).isNotNull();
166+
}
167+
168+
// Test helper classes
169+
@Data
170+
@Builder
171+
private static class TestClass {
172+
private String name;
173+
private int value;
174+
}
175+
176+
@Data
177+
@Builder
178+
private static class TestClassWithList {
179+
@Singular
180+
private List<String> items;
181+
}
182+
183+
private record SimpleTestClass(String name) {
184+
}
185+
186+
@Getter
187+
private static class MutableTestClass {
188+
private boolean reset = false;
189+
190+
public void reset() {
191+
this.reset = true;
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)