-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
unit OPP.Text; | ||
|
||
{$mode ObjFPC}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
, SysUtils | ||
; | ||
|
||
type | ||
{ TTextFileType } | ||
TTextFileType = (tftUnknnown, tftAnsi, tftUTF8, tftUTF16, tftUTF32); | ||
|
||
{ TTextCharType } | ||
TTextCharType = (tctUnknown, tctAnsi, tctUTF8, tctUTF16, tctUTF32); | ||
|
||
{ #todo 999 -ogcarreno : Determine if a union is possible or best } | ||
{ TTextCharacter } | ||
TTextCharacter = record | ||
&Type: TTextCharType; | ||
Ansi: Char; | ||
UTF8: String; | ||
UTF16: String; | ||
UTF32: String; | ||
end; | ||
|
||
implementation | ||
|
||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
unit OPP.Text.SourceFile; | ||
|
||
{$mode ObjFPC}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
, SysUtils | ||
, OPP.Text | ||
; | ||
|
||
type | ||
{ ETextSourceFileDoesNotExist } | ||
ETextSourceFileDoesNotExist = class(Exception); | ||
|
||
{ TTextSourceFile } | ||
TTextSourceFile = class(TObject) | ||
private | ||
FSourceFileStream: TFileStream; | ||
protected | ||
public | ||
constructor Create(const AFileName: String); | ||
destructor Destroy; override; | ||
|
||
function GetNextChar: TTextCharacter; | ||
published | ||
end; | ||
|
||
resourcestring | ||
rsETextSourceFileDoesNotExist = 'File "%s" does not exist'; | ||
|
||
implementation | ||
|
||
{ TTextSourceFile } | ||
|
||
constructor TTextSourceFile.Create(const AFileName: String); | ||
begin | ||
FSourceFileStream:= nil; | ||
if not FileExists(AFileName) then raise ETextSourceFileDoesNotExist.Create( | ||
Format( | ||
rsETextSourceFileDoesNotExist, | ||
[ AFileName ] | ||
) | ||
); | ||
|
||
FSourceFileStream:= TFileStream.Create(AFileName, fmOpenRead); | ||
end; | ||
|
||
destructor TTextSourceFile.Destroy; | ||
begin | ||
if Assigned(FSourceFileStream) then FSourceFileStream.Free; | ||
inherited Destroy; | ||
end; | ||
|
||
function TTextSourceFile.GetNextChar: TTextCharacter; | ||
begin | ||
Result.&Type:= tctUnknown; | ||
Result.Ansi := #0; | ||
Result.UTF8 := ''; | ||
Result.UTF16:= ''; | ||
Result.UTF32:= ''; | ||
|
||
// Get next char(s) and fill record | ||
end; | ||
|
||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
tests/TestObjectPascalParser.lpr → tests/TestObjectPascalParserCLI.lpr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
unit TestObjectPascalParserTextSourceFile; | ||
|
||
{$mode objfpc}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
, SysUtils | ||
, fpcunit | ||
//, testutils | ||
, testregistry | ||
, OPP.Text | ||
, OPP.Text.SourceFile | ||
; | ||
|
||
type | ||
|
||
{ TTestObjectPascalParserTextSourceFile } | ||
|
||
TTestObjectPascalParserTextSourceFile= class(TTestCase) | ||
private | ||
FSourceFile: TTextSourceFile; | ||
|
||
procedure TestSourceFileCreateException; | ||
published | ||
procedure TestObjectPascalParserTextSourceFileCreate; | ||
procedure TestObjectPascalParserTextSourceFileCreateError; | ||
end; | ||
|
||
implementation | ||
|
||
const | ||
cSourceFileContentUTF8 = 'program Test🌟'; | ||
|
||
procedure TTestObjectPascalParserTextSourceFile.TestSourceFileCreateException; | ||
begin | ||
FSourceFile:= TTextSourceFile.Create(''); | ||
end; | ||
|
||
procedure TTestObjectPascalParserTextSourceFile.TestObjectPascalParserTextSourceFileCreate; | ||
var | ||
stringStream: TstringStream; | ||
tmpFilename: String; | ||
begin | ||
stringStream:= TStringStream.Create(cSourceFileContentUTF8); | ||
try | ||
tmpFilename:= GetTempFileName; | ||
stringStream.SaveToFile(tmpFilename); | ||
try | ||
|
||
FSourceFile:= TTextSourceFile.Create(tmpFilename); | ||
AssertNotNull('Text Source File is not null', FSourceFile); | ||
// Assert file is of type tftUTF8 | ||
|
||
finally | ||
DeleteFile(tmpFilename); | ||
end; | ||
finally | ||
stringStream.Free; | ||
end; | ||
end; | ||
|
||
procedure TTestObjectPascalParserTextSourceFile.TestObjectPascalParserTextSourceFileCreateError; | ||
begin | ||
FSourceFile:= nil; | ||
AssertException( | ||
'Text Source File Doesn Not Exists Exception', | ||
ETextSourceFileDoesNotExist, | ||
@TestSourceFileCreateException, | ||
Format( | ||
rsETextSourceFileDoesNotExist, | ||
[ '' ] | ||
) | ||
); | ||
if Assigned(FSourceFile) then FSourceFile.Free; | ||
end; | ||
|
||
|
||
|
||
initialization | ||
|
||
RegisterTest(TTestObjectPascalParserTextSourceFile); | ||
end. | ||
|