mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 20:32:15 +00:00
commit
fa0e7d1dea
27
rescript/.gitignore
vendored
Normal file
27
rescript/.gitignore
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
*.exe
|
||||||
|
*.obj
|
||||||
|
*.out
|
||||||
|
*.compile
|
||||||
|
*.native
|
||||||
|
*.byte
|
||||||
|
*.cmo
|
||||||
|
*.annot
|
||||||
|
*.cmi
|
||||||
|
*.cmx
|
||||||
|
*.cmt
|
||||||
|
*.cmti
|
||||||
|
*.cma
|
||||||
|
*.a
|
||||||
|
*.cmxa
|
||||||
|
*.obj
|
||||||
|
*~
|
||||||
|
*.annot
|
||||||
|
*.cmj
|
||||||
|
*.bak
|
||||||
|
lib/bs
|
||||||
|
*.mlast
|
||||||
|
*.mliast
|
||||||
|
.vscode
|
||||||
|
.merlin
|
||||||
|
.bsb.lock
|
||||||
|
/node_modules/
|
||||||
35
rescript/README.md
Normal file
35
rescript/README.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Gilded Rose
|
||||||
|
|
||||||
|
This is the Gilded Rose kata in Rescript with Jest
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Install dependencies
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running tests
|
||||||
|
|
||||||
|
To run all tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn test
|
||||||
|
```
|
||||||
|
|
||||||
|
To run all tests in watch mode
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn test:watch
|
||||||
|
```
|
||||||
|
|
||||||
|
To start developing
|
||||||
|
```sh
|
||||||
|
yarn dev:rescript
|
||||||
|
```
|
||||||
|
|
||||||
|
To run the TextTest file
|
||||||
|
```sh
|
||||||
|
yarn texttest [days]
|
||||||
|
```
|
||||||
14
rescript/bsconfig.json
Normal file
14
rescript/bsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "rescript",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"sources": {
|
||||||
|
"dir" : "src",
|
||||||
|
"subdirs" : true
|
||||||
|
},
|
||||||
|
"package-specs": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"in-source": true
|
||||||
|
},
|
||||||
|
"suffix": ".bs.js",
|
||||||
|
"bs-dependencies": ["@glennsl/rescript-jest"]
|
||||||
|
}
|
||||||
14
rescript/jest.config.js
Normal file
14
rescript/jest.config.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
moduleFileExtensions: [
|
||||||
|
"js",
|
||||||
|
"mjs",
|
||||||
|
],
|
||||||
|
testMatch: [
|
||||||
|
"**/src/**/*_test.mjs",
|
||||||
|
"**/src/**/*_test.bs.js",
|
||||||
|
],
|
||||||
|
transform: {
|
||||||
|
"^.+\\.jsx?$": "esbuild-jest"
|
||||||
|
},
|
||||||
|
"transformIgnorePatterns": ["<rootDir>/node_modules/(?!(rescript|@glennsl/rescript-jest)/)"]
|
||||||
|
}
|
||||||
22
rescript/package.json
Normal file
22
rescript/package.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.22.15",
|
||||||
|
"@babel/preset-env": "^7.22.15",
|
||||||
|
"@glennsl/rescript-jest": "^0.10.0",
|
||||||
|
"babel-jest": "^29.6.4",
|
||||||
|
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
||||||
|
"esbuild": "^0.19.2",
|
||||||
|
"esbuild-jest": "^0.5.0",
|
||||||
|
"jest": "^29.6.4",
|
||||||
|
"rescript": "^10.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watchAll",
|
||||||
|
"dev:rescript": "rescript build -w",
|
||||||
|
"texttest": "node src/TextTest.bs.js"
|
||||||
|
},
|
||||||
|
"name": "rescript",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
102
rescript/src/GildedRose.bs.js
Normal file
102
rescript/src/GildedRose.bs.js
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
function make(name, sellIn, quality) {
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
sellIn: sellIn,
|
||||||
|
quality: quality
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var Item = {
|
||||||
|
make: make
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateQuality(items) {
|
||||||
|
return items.map(function (item) {
|
||||||
|
var newItem = item;
|
||||||
|
if (newItem.name !== "Aged Brie" && newItem.name !== "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (newItem.quality > 0 && newItem.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
var init = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init.name,
|
||||||
|
sellIn: init.sellIn,
|
||||||
|
quality: newItem.quality - 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (newItem.quality < 50) {
|
||||||
|
var init$1 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$1.name,
|
||||||
|
sellIn: init$1.sellIn,
|
||||||
|
quality: newItem.quality + 1 | 0
|
||||||
|
};
|
||||||
|
if (newItem.name === "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (newItem.sellIn < 11 && newItem.quality < 50) {
|
||||||
|
var init$2 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$2.name,
|
||||||
|
sellIn: init$2.sellIn,
|
||||||
|
quality: newItem.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (newItem.sellIn < 6 && newItem.quality < 50) {
|
||||||
|
var init$3 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$3.name,
|
||||||
|
sellIn: init$3.sellIn,
|
||||||
|
quality: newItem.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (newItem.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
var init$4 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$4.name,
|
||||||
|
sellIn: newItem.sellIn - 1 | 0,
|
||||||
|
quality: init$4.quality
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (newItem.sellIn < 0) {
|
||||||
|
if (newItem.name !== "Aged Brie") {
|
||||||
|
if (newItem.name !== "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (newItem.quality > 0 && newItem.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
var init$5 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$5.name,
|
||||||
|
sellIn: init$5.sellIn,
|
||||||
|
quality: newItem.quality - 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var init$6 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$6.name,
|
||||||
|
sellIn: init$6.sellIn,
|
||||||
|
quality: newItem.quality - newItem.quality | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (newItem.quality < 50) {
|
||||||
|
var init$7 = newItem;
|
||||||
|
newItem = {
|
||||||
|
name: init$7.name,
|
||||||
|
sellIn: init$7.sellIn,
|
||||||
|
quality: newItem.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return newItem;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Item = Item;
|
||||||
|
exports.updateQuality = updateQuality;
|
||||||
|
/* No side effect */
|
||||||
71
rescript/src/GildedRose.res
Normal file
71
rescript/src/GildedRose.res
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
module Item = {
|
||||||
|
type t = {
|
||||||
|
name: string,
|
||||||
|
sellIn: int,
|
||||||
|
quality: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
let make = (~name, ~sellIn, ~quality): t => {
|
||||||
|
name,
|
||||||
|
sellIn,
|
||||||
|
quality,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let updateQuality = (items: array<Item.t>) => {
|
||||||
|
items->Js.Array2.map(item => {
|
||||||
|
let newItem = ref(item)
|
||||||
|
|
||||||
|
if (
|
||||||
|
newItem.contents.name != "Aged Brie" &&
|
||||||
|
newItem.contents.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
) {
|
||||||
|
if newItem.contents.quality > 0 {
|
||||||
|
if newItem.contents.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality - 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if newItem.contents.quality < 50 {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality + 1}
|
||||||
|
|
||||||
|
if newItem.contents.name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if newItem.contents.sellIn < 11 {
|
||||||
|
if newItem.contents.quality < 50 {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if newItem.contents.sellIn < 6 {
|
||||||
|
if newItem.contents.quality < 50 {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if newItem.contents.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...newItem.contents, sellIn: newItem.contents.sellIn - 1}
|
||||||
|
}
|
||||||
|
|
||||||
|
if newItem.contents.sellIn < 0 {
|
||||||
|
if newItem.contents.name != "Aged Brie" {
|
||||||
|
if newItem.contents.name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if newItem.contents.quality > 0 {
|
||||||
|
if newItem.contents.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality - 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newItem := {
|
||||||
|
...newItem.contents,
|
||||||
|
quality: newItem.contents.quality - newItem.contents.quality,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if newItem.contents.quality < 50 {
|
||||||
|
newItem := {...newItem.contents, quality: newItem.contents.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newItem.contents
|
||||||
|
})
|
||||||
|
}
|
||||||
20
rescript/src/GildedRose_test.bs.js
Normal file
20
rescript/src/GildedRose_test.bs.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Jest = require("@glennsl/rescript-jest/src/jest.bs.js");
|
||||||
|
var Caml_array = require("rescript/lib/js/caml_array.js");
|
||||||
|
var GildedRose = require("./GildedRose.bs.js");
|
||||||
|
|
||||||
|
Jest.describe("Gilded Rose", (function (param) {
|
||||||
|
Jest.test("should foo", (function (param) {
|
||||||
|
var items = [{
|
||||||
|
name: "foo",
|
||||||
|
sellIn: 0,
|
||||||
|
quality: 0
|
||||||
|
}];
|
||||||
|
var updatedItems = GildedRose.updateQuality(items);
|
||||||
|
return Jest.Expect.toBe(Jest.Expect.expect(Caml_array.get(updatedItems, 0).name), "fixme");
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
|
||||||
|
/* Not a pure module */
|
||||||
11
rescript/src/GildedRose_test.res
Normal file
11
rescript/src/GildedRose_test.res
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
open Jest
|
||||||
|
open Expect
|
||||||
|
open GildedRose
|
||||||
|
|
||||||
|
describe("Gilded Rose", () => {
|
||||||
|
test("should foo", () => {
|
||||||
|
let items: array<Item.t> = [{name: "foo", sellIn: 0, quality: 0}]
|
||||||
|
let updatedItems = updateQuality(items)
|
||||||
|
expect(updatedItems[0].name)->toBe("fixme")
|
||||||
|
})
|
||||||
|
})
|
||||||
42
rescript/src/TextTest.bs.js
Normal file
42
rescript/src/TextTest.bs.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Process = require("process");
|
||||||
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
||||||
|
var Caml_array = require("rescript/lib/js/caml_array.js");
|
||||||
|
var GildedRose = require("./GildedRose.bs.js");
|
||||||
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
||||||
|
var Caml_format = require("rescript/lib/js/caml_format.js");
|
||||||
|
|
||||||
|
console.log("OMGHAI!");
|
||||||
|
|
||||||
|
var items = {
|
||||||
|
contents: [
|
||||||
|
GildedRose.Item.make("+5 Dexterity Vest", 10, 20),
|
||||||
|
GildedRose.Item.make("Aged Brie", 2, 0),
|
||||||
|
GildedRose.Item.make("Elixir of the Mongoose", 5, 7),
|
||||||
|
GildedRose.Item.make("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||||
|
GildedRose.Item.make("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
|
GildedRose.Item.make("Conjured Mana Cake", 3, 6)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var days = Belt_Option.mapWithDefault(Belt_Array.get(Process.argv, 2), 31, Caml_format.int_of_string);
|
||||||
|
|
||||||
|
for(var i = 0; i <= days; ++i){
|
||||||
|
console.log("-------- day " + String(i) + " --------");
|
||||||
|
console.log("name, sellIn, quality");
|
||||||
|
for(var j = 0 ,j_finish = items.contents.length; j < j_finish; ++j){
|
||||||
|
var item = Caml_array.get(items.contents, j);
|
||||||
|
console.log(item.name + ", " + String(item.sellIn) + ", " + String(item.quality));
|
||||||
|
}
|
||||||
|
console.log("");
|
||||||
|
items.contents = GildedRose.updateQuality(items.contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.items = items;
|
||||||
|
exports.days = days;
|
||||||
|
/* Not a pure module */
|
||||||
28
rescript/src/TextTest.res
Normal file
28
rescript/src/TextTest.res
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
open GildedRose
|
||||||
|
|
||||||
|
Js.log("OMGHAI!")
|
||||||
|
|
||||||
|
let items: ref<array<Item.t>> = ref([
|
||||||
|
Item.make(~name="+5 Dexterity Vest", ~sellIn=10, ~quality=20),
|
||||||
|
Item.make(~name="Aged Brie", ~sellIn=2, ~quality=0),
|
||||||
|
Item.make(~name="Elixir of the Mongoose", ~sellIn=5, ~quality=7),
|
||||||
|
Item.make(~name="Sulfuras, Hand of Ragnaros", ~sellIn=0, ~quality=80),
|
||||||
|
Item.make(~name="Sulfuras, Hand of Ragnaros", ~sellIn=-1, ~quality=80),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=15, ~quality=20),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=10, ~quality=49),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=5, ~quality=49),
|
||||||
|
Item.make(~name="Conjured Mana Cake", ~sellIn=3, ~quality=6),
|
||||||
|
])
|
||||||
|
|
||||||
|
let days = Node.Process.argv->Belt.Array.get(2)->Belt.Option.mapWithDefault(31, int_of_string)
|
||||||
|
|
||||||
|
for i in 0 to days {
|
||||||
|
Js.log("-------- day " ++ string_of_int(i) ++ " --------")
|
||||||
|
Js.log("name, sellIn, quality")
|
||||||
|
for j in 0 to Js.Array2.length(items.contents) - 1 {
|
||||||
|
let item = items.contents[j]
|
||||||
|
Js.log(item.name ++ ", " ++ string_of_int(item.sellIn) ++ ", " ++ string_of_int(item.quality))
|
||||||
|
}
|
||||||
|
Js.log("")
|
||||||
|
items := updateQuality(items.contents)
|
||||||
|
}
|
||||||
5268
rescript/yarn.lock
Normal file
5268
rescript/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user