1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-12-01 09:06:43 +02:00

Проверка модификации ключей структуры вне функции-конструктора #1054 (#1393)

This commit is contained in:
Dmitriy Marmyshev
2023-12-22 13:35:42 -08:00
committed by GitHub
parent 3218c8665c
commit dad25b744f
11 changed files with 559 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
// @strict-types
Procedure Incorrect1() Export
TestStucture = Correct2();
TestStucture.Clear();
TestStucture.Delete("Key2");
TestStucture.Insert("Key1", Undefined);
TestStucture.Clear();
TestStucture.Insert("Key1", 10);
TestStucture.Key1 = "";
EndProcedure
Procedure Correct1() Export
TestStucture = new Structure();
TestStucture.Clear();
TestStucture.Delete("Key2");
TestStucture.Insert("Key1");
TestStucture.Clear();
TestStucture.Insert("Key1", 10);
TestStucture.Clear();
TestStucture.Key1 = "";
EndProcedure
// Parameters:
// TestStucture - Structure:
// * Key1 - Boolean -
// * Key2 - Number -
Procedure Incorrect2(TestStucture) Export
TestStucture.Insert("Key1", 10);
TestStucture.Insert("Key3", 10);
TestStucture.Clear();
TestStucture.Delete("Key2");
EndProcedure
// Parameters:
// TestStucture - See Correct2
Procedure Incorrect3(TestStucture) Export
TestStucture.Insert("Key1", 10);
TestStucture.Insert("Key3", 10);
TestStucture.Clear();
TestStucture.Delete("Key2");
EndProcedure
// Returns:
// Structure:
// * Key1 - Boolean -
// * Key2 - Number -
Function Correct2() Export
TestStucture = new Structure("Key1, Key2", true, 10);
TestStucture.Insert("Key1", 10);
Return TestStucture;
EndFunction

View File

@@ -55,6 +55,7 @@ import com.e1c.v8codestyle.bsl.strict.check.InvocationParamIntersectionCheck;
import com.e1c.v8codestyle.bsl.strict.check.MethodParamTypeCheck;
import com.e1c.v8codestyle.bsl.strict.check.SimpleStatementTypeCheck;
import com.e1c.v8codestyle.bsl.strict.check.StructureCtorValueTypeCheck;
import com.e1c.v8codestyle.bsl.strict.check.StructureKeyModificationCheck;
import com.e1c.v8codestyle.bsl.strict.check.TypedValueAddingToUntypedCollectionCheck;
import com.e1c.v8codestyle.bsl.strict.check.VariableTypeCheck;
@@ -643,6 +644,33 @@ public class CommonModuleStrictTypesTest
assertEquals(Set.of("18", "19"), lines);
}
/**
* Test of {@link StructureKeyModificationCheck} that check replace existing key of external structure key,
* delete key or clear structure with existing keys.
*
* @throws Exception the exception
*/
@Test
public void testStructureKeyModification() throws Exception
{
String checkId = "structure-key-modification";
String resouceName = "structure-key-modification";
Module module = updateAndGetModule(resouceName);
List<Marker> markers = getMarters(checkId, module);
assertEquals(10, markers.size());
Set<String> lines = new HashSet<>();
for (Marker marker : markers)
{
lines.add(marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
assertEquals(Set.of("7", "8", "9", "10", "36", "38", "39", "47", "49", "50"), lines);
}
private IDtProject getProject()
{
return dtProject;