|
| 1 | +package org.modelix.model.mpsadapters |
| 2 | + |
| 3 | +import jetbrains.mps.smodel.SModelId |
| 4 | +import jetbrains.mps.smodel.SModelReference |
| 5 | +import org.jetbrains.mps.openapi.persistence.PersistenceFacade |
| 6 | +import java.util.UUID |
| 7 | +import kotlin.test.assertFailsWith |
| 8 | + |
| 9 | +class ModelReferenceParsingTest : MpsAdaptersTestBase("SimpleProject") { |
| 10 | + |
| 11 | + fun `test model reference can be serialized and deserialized`() { |
| 12 | + val originalReference = SModelReference(null, SModelId.regular(UUID.fromString("9858ad24-9b93-4fb4-b55d-1d5b38a5d03b")), "my.model") |
| 13 | + val referenceWithoutName = SModelReference(null, SModelId.regular(UUID.fromString("9858ad24-9b93-4fb4-b55d-1d5b38a5d03b")), "") |
| 14 | + assertEquals("r:9858ad24-9b93-4fb4-b55d-1d5b38a5d03b()", referenceWithoutName.toString()) |
| 15 | + |
| 16 | + // MPS fails to parse a reference that it serialized itself. |
| 17 | + // This can be considered an MPS bug, but we have to compensate for that. |
| 18 | + // This check ensures that we found the correct cause for this exception. |
| 19 | + assertFailsWith(PersistenceFacade.IncorrectModelReferenceFormatException::class) { |
| 20 | + PersistenceFacade.getInstance().createModelReference(referenceWithoutName.toString()) |
| 21 | + } |
| 22 | + |
| 23 | + // Modelix is expected to remove the name, because MPS ignores the name when comparing two model references. |
| 24 | + // By not storing the name in Modelix we avoid any inconsistent behavior after a model renaming. |
| 25 | + assertEquals("mps-model:r:9858ad24-9b93-4fb4-b55d-1d5b38a5d03b", originalReference.toModelix().serialize()) |
| 26 | + |
| 27 | + // Ensure a reference is still parsable by MPS after it was converted to and from Modelix. |
| 28 | + assertEquals( |
| 29 | + "r:9858ad24-9b93-4fb4-b55d-1d5b38a5d03b(unknown)", |
| 30 | + PersistenceFacade.getInstance().createModelReference(originalReference.toModelix().toMPS().toString()).toString(), |
| 31 | + ) |
| 32 | + } |
| 33 | +} |
0 commit comments