Moved all old tests to another folder
This commit is contained in:
parent
960770d73f
commit
2ad6dfabab
15 changed files with 8 additions and 8 deletions
39
tests/old_tests/example_project/README.md
Normal file
39
tests/old_tests/example_project/README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Example Project
|
||||
|
||||
This is a simple library that provides very basic functionality,
|
||||
this project is a means to test the compiler capabilities of NCC
|
||||
|
||||
|
||||
### Generating a project configuration file.
|
||||
|
||||
You can generate a project configuration file using the NCC
|
||||
command-line interface, you should run the command in the
|
||||
root directory of your project rather than the source directory.
|
||||
|
||||
The argument `src` allows you to specify the source directory
|
||||
which is required, otherwise NCC will assume the src directory is the current working directory.
|
||||
|
||||
```shell
|
||||
$ ls
|
||||
README.md src
|
||||
|
||||
$ ncc project create --src="src/ExampleLibrary" --package="com.example.library" --name="ExampleLibrary"
|
||||
Project successfully created
|
||||
|
||||
$ ls
|
||||
ncc project.json README.md src
|
||||
```
|
||||
|
||||
Upon creating the project, you will see a directory named `ncc`
|
||||
and a file named `project.json`, the `ncc` directory will simply
|
||||
contain extra information about the project, the file `project.json`
|
||||
contains information about the project itself, you can modify
|
||||
and change the contents of the project accordingly
|
||||
|
||||
This process only needs to be done once, any additional changes
|
||||
can be done manually by editing project.json
|
||||
|
||||
Once project.json is created, the project can be compiled using NCC
|
||||
|
||||
|
||||
### Compiling the project
|
3
tests/old_tests/example_project/scripts/unit.bash
Normal file
3
tests/old_tests/example_project/scripts/unit.bash
Normal file
|
@ -0,0 +1,3 @@
|
|||
echo "Hello World!"
|
||||
read -r -p "What is your name? " name
|
||||
echo "Hello $name"
|
4
tests/old_tests/example_project/scripts/unit.lua
Normal file
4
tests/old_tests/example_project/scripts/unit.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
print("Hello World!")
|
||||
print("What is your name?")
|
||||
name = io.read()
|
||||
print("Hello " .. name)
|
6
tests/old_tests/example_project/scripts/unit.pl
Normal file
6
tests/old_tests/example_project/scripts/unit.pl
Normal file
|
@ -0,0 +1,6 @@
|
|||
use warnings;
|
||||
print("Hello, World!\n");
|
||||
print("What is your name? ");
|
||||
my $name = <STDIN>;
|
||||
chomp($name);
|
||||
print("Hello, $name\n");
|
3
tests/old_tests/example_project/scripts/unit.py2
Normal file
3
tests/old_tests/example_project/scripts/unit.py2
Normal file
|
@ -0,0 +1,3 @@
|
|||
print('Hello World!')
|
||||
name = input('What is your name? ')
|
||||
print('Hello', name)
|
3
tests/old_tests/example_project/scripts/unit.py3
Normal file
3
tests/old_tests/example_project/scripts/unit.py3
Normal file
|
@ -0,0 +1,3 @@
|
|||
print('Hello World!')
|
||||
name = input('What is your name? ')
|
||||
print('Hello', name)
|
File diff suppressed because it is too large
Load diff
88799
tests/old_tests/example_project/src/ExampleLibrary/Data/last_names.txt
Normal file
88799
tests/old_tests/example_project/src/ExampleLibrary/Data/last_names.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace old_tests\example_project\src\ExampleLibrary;
|
||||
|
||||
use old_tests\example_project\src\ExampleLibrary\Exceptions\FileNotFoundException;
|
||||
use old_tests\example_project\src\ExampleLibrary\Objects\Person;
|
||||
|
||||
class ExampleLibrary
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $FirstNames;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $LastNames;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'first_names.txt'))
|
||||
throw new FileNotFoundException('The file first_names.txt does not exist in the data directory.');
|
||||
|
||||
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'last_names.txt'))
|
||||
throw new FileNotFoundException('The file last_names.txt does not exist in the data directory.');
|
||||
|
||||
$first_names = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'first_names.txt');
|
||||
$this->FirstNames = explode("\n", $first_names);
|
||||
|
||||
$last_names = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'last_names.txt');
|
||||
$this->LastNames = explode("\n", $last_names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of randomly generated
|
||||
*
|
||||
* @param int $amount
|
||||
* @return array
|
||||
* @throws \old_tests\example_project\src\ExampleLibrary\Exceptions\InvalidNameException
|
||||
*/
|
||||
public function generatePeople(int $amount=10): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
for ($k = 0 ; $k < $amount; $k++)
|
||||
{
|
||||
$FullName = implode(' ', [
|
||||
$this->FirstNames[array_rand($this->FirstNames)],
|
||||
$this->LastNames[array_rand($this->LastNames)]
|
||||
]);
|
||||
|
||||
$results[] = new Person($FullName);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpPropertyOnlyWrittenInspection */
|
||||
|
||||
namespace old_tests\example_project\src\ExampleLibrary\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class FileNotFoundException extends Exception
|
||||
{
|
||||
/**
|
||||
* @var Throwable|null
|
||||
*/
|
||||
private ?Throwable $previous;
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->previous = $previous;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpPropertyOnlyWrittenInspection */
|
||||
|
||||
namespace old_tests\example_project\src\ExampleLibrary\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class InvalidNameException extends Exception
|
||||
{
|
||||
private ?Throwable $previous;
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
$this->message = $message;
|
||||
$this->code = $code;
|
||||
$this->previous = $previous;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace old_tests\example_project\src\ExampleLibrary\Objects;
|
||||
|
||||
use old_tests\example_project\src\ExampleLibrary\Exceptions\InvalidNameException;
|
||||
|
||||
class Person
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $FirstName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $LastName;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @param string|null $name
|
||||
* @throws InvalidNameException
|
||||
*/
|
||||
public function __construct(?string $name=null)
|
||||
{
|
||||
if($name !== null)
|
||||
{
|
||||
$exploded_name = explode(' ', $name);
|
||||
|
||||
if(count($exploded_name) < 2)
|
||||
{
|
||||
throw new InvalidNameException('The given name must contain a first and last name.');
|
||||
}
|
||||
|
||||
$this->FirstName = $exploded_name[0];
|
||||
$this->LastName = $exploded_name[1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the first name of the person.
|
||||
*
|
||||
* @param string $FirstName
|
||||
*/
|
||||
public function setFirstName(string $FirstName): void
|
||||
{
|
||||
$this->FirstName = $FirstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last name of the person.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName(): string
|
||||
{
|
||||
return $this->LastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last name of the person.
|
||||
*
|
||||
* @param string $LastName
|
||||
*/
|
||||
public function setLastName(string $LastName): void
|
||||
{
|
||||
$this->LastName = $LastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first name of the person.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName(): string
|
||||
{
|
||||
return $this->FirstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the person.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return implode(' ', [$this->FirstName, $this->LastName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the person
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'first_name' => $this->FirstName,
|
||||
'last_name' => $this->LastName
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return Person
|
||||
*/
|
||||
public static function fromArray(array $data): Person
|
||||
{
|
||||
$person = new Person();
|
||||
|
||||
if(isset($data['first_name']))
|
||||
$person->FirstName = $data['first_name'];
|
||||
|
||||
if(isset($data['last_name']))
|
||||
$person->LastName = $data['last_name'];
|
||||
|
||||
return $person;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue