-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial formatter schema #12
base: master
Are you sure you want to change the base?
Changes from 1 commit
795b99c
a4d238e
4517414
16d7123
39b3605
cfe58ae
731cd27
5c61e26
7693f72
f2333d4
5a56353
f196456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,20 @@ import { createUniversalDataDefinitionLanguageServices } from "../../src/languag | |
import { EmptyFileSystem } from "langium"; | ||
import { expectFormatting } from "langium/test"; | ||
|
||
const universalDataDefinitionLanguageService =createUniversalDataDefinitionLanguageServices({...EmptyFileSystem,}).UniversalDataDefinitionLanguage; | ||
const universalDataDefinitionLanguageFormatting = expectFormatting(universalDataDefinitionLanguageService | ||
); | ||
const universalDataDefinitionLanguageService = createUniversalDataDefinitionLanguageServices({...EmptyFileSystem,}).UniversalDataDefinitionLanguage; | ||
const universalDataDefinitionLanguageFormatting = expectFormatting(universalDataDefinitionLanguageService); | ||
|
||
describe("Universal Data Definition Language Formatter", () => { | ||
it("should format cdm array with conceptual elemnt", async () => { | ||
it("should format cdm array", async () => { | ||
await universalDataDefinitionLanguageFormatting({ | ||
before: | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; domain cdmDomain "Entry for conceptual domain"; cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', | ||
after: `dm PPT "Base data structures to support People, Places and Things" | ||
{ | ||
|
||
cdm Conceptual "Need to start at Conceptual Level" | ||
{ | ||
|
||
basis uddlBasis "Formating conceptual basis entity"; | ||
domain cdmDomain "Entry for conceptual domain"; | ||
cdm anothercdm "A cdm with another data" | ||
{ | ||
|
||
|
@@ -27,14 +24,14 @@ describe("Universal Data Definition Language Formatter", () => { | |
|
||
} | ||
|
||
}` | ||
}`, | ||
}); | ||
}); | ||
|
||
it("should format conceptual element", async () => { | ||
it("should format cdm with conceptual association", async () => { | ||
await universalDataDefinitionLanguageFormatting({ | ||
before: | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};centity AddressableEntity "Any entity that is addressable in some way" {};}}', | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', | ||
after: `dm PPT "Base data structures to support People, Places and Things" | ||
{ | ||
|
||
|
@@ -46,14 +43,84 @@ describe("Universal Data Definition Language Formatter", () => { | |
|
||
}; | ||
|
||
} | ||
|
||
}`, | ||
}); | ||
}); | ||
|
||
it("should format cdm with conceptual entity", async () => { | ||
await universalDataDefinitionLanguageFormatting({ | ||
before: | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', | ||
after: `dm PPT "Base data structures to support People, Places and Things" | ||
{ | ||
|
||
cdm Conceptual "Need to start at Conceptual Level" | ||
{ | ||
|
||
centity AddressableEntity "Any entity that is addressable in some way" | ||
{ | ||
|
||
}; | ||
|
||
} | ||
|
||
}` | ||
}`, | ||
}); | ||
}); | ||
}); | ||
|
||
it('should format cdm with conceptual basis',async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you can have tests for each individual type, you may find that a test that combines multiple types is sufficient. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a previous commit, I merged conceptual entities and conceptual associations into one test case. During this process, only formatter for conceptual entities was checked. I then attempted to verify whether I would encounter similar behavior for conceptual basis and conceptual domain as well. |
||
await universalDataDefinitionLanguageFormatting({ | ||
before: | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', | ||
after: `dm PPT "Base data structures to support People, Places and Things" | ||
{ | ||
|
||
cdm Conceptual "Need to start at Conceptual Level" | ||
{ | ||
|
||
basis uddlBasis "Formating conceptual basis entity"; | ||
} | ||
|
||
}`, | ||
}) | ||
}) | ||
|
||
it('should format cdm with conceptual domain',async () => { | ||
await universalDataDefinitionLanguageFormatting({ | ||
before: | ||
'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', | ||
after: `dm PPT "Base data structures to support People, Places and Things" | ||
{ | ||
|
||
cdm Conceptual "Need to start at Conceptual Level" | ||
{ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really want all these blank lines after formatting? You've got a blank line after every '{' and '}'. That's going to make some files a lot longer - which will force users to scroll. When people have to scroll, they forget what they can't see - which makes it harder to understand complex content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test would not pass without the blank lines in the after block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When a test does not pass, you have a choice: change the test (what you did) or change the code being tested. The point I'm making above is that the formatter currently inserts those blank lines - which is why your test needs the blank lines to pass. My question is: do you want the formatter to do that? The goal of formatting is to put the text into a format that is easy to read and understand. Every decision you make about how the formatter works should be made with that in mind. |
||
domain NaturalPerson "Base definition of a natural person"; | ||
} | ||
|
||
}`, | ||
}) | ||
}) | ||
|
||
it("should format ldm array",async () => { | ||
await universalDataDefinitionLanguageFormatting({ | ||
before: 'dm Book "Base definition for book requirement" {ldm library "contains available books" {ldm BookShelf "Books related by category"{}}}', | ||
after: `dm Book "Base definition for book requirement" | ||
{ | ||
|
||
ldm library "contains available books" | ||
{ | ||
|
||
ldm BookShelf "Books related by category" | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
||
}` | ||
}) | ||
}) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your current tests, all the 'before' text is on a single line. You should also have the same tests where the 'before' text has each token on a separate line (you can do this with a find/replace that replaces blanks the
before
text with CRs).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted