تعرّف على كيفية اختبار تمارين ReScript على Exercism
استخدم واجهة سطر الأوامر الخاصة بـ Exercism لتنزيل التمرين الذي تريد العمل عليه.
exercism download --track=rescript --exercise=hello-world
ثم انتقل إلى مجلد التمرين.
cd /path/to/exercism/rescript/hello-world
قبل تشغيل الاختبارات، ثبّت تبعيات التمرين.
npm install
استخدم exercism test أو npm run test لترجمة مجموعة الاختبارات المرفقة وتشغيلها.
يعرض مشغّل الاختبارات كل اختبار مع حالة النجاح أو الفشل.
1/3: no name given
PASS - no name given
2/3: a name given
FAIL - a name given
---
operator: equal
left: One for you, one for me.
right: One for Alice, one for me.
...
3/3: another name given
FAIL - another name given
---
operator: equal
left: One for you, one for me.
right: One for Bob, one for me.
...
# Ran 3 tests (3 assertions)
# 1 passed
# 2 failed
left هو ما أرجعه الكود، أما right فهو ما توقّعه الاختبار.
two-fer/
├── src/
│ ├── TwoFer.res // your solution goes here
│ └── TwoFer.resi // the optional interface file containing signatures
├── tests/
│ └── TwoFer_test.res // your test suite
├── package.json // used to install project dependencies
└── ...
ملف TwoFer.resi هنا هو ملف واجهة اختياري.
عند وجوده، فإنه يحدد توقيعات الدوال التي يجب أن يستوفيها حلك، ويمكن أن يكون تلميحًا لما ينبغي تنفيذه.
على سبيل المثال، إذا أعلنت الواجهة عن:
let hello: unit => string
فينبغي أن يعرّف تنفيذك:
let hello = () => "Hello, World!"
إذا لم يُترجم كودك، فإن مترجم ReScript ينتج رسائل خطأ مفصّلة تحدد الموقع الدقيق والأنواع المتوقعة.
We've found a bug for you!
1 │ let x: string = 42
This has type: int
But it's expected to have type: string
You can convert int to string with Int.toString.
اقرأ رسالة الخطأ بعناية، فهي عادةً تشير مباشرةً إلى المشكلة.