User:TomTheHand/Unit tests for AWB regexes
Hi there! This is my testing page for my AWB regular expressions. I realized that I really needed to perform unit testing on my regexes to make sure they all worked properly, so I started up these pages. I then realized that if I also provide the regexes themselves, people might be able to come by and use them.
I've used <small> tags on the really lengthy ones to try to shrink the width of the table. I realize that this makes many of them illegible, but you can copy and paste them elsewhere for study. I also realize some tables are still horrifyingly wide and will not fit on screens with a resolution less than 1024 pixels wide. Sorry 'bout that.
In order to use them:
- Fire up AWB.
- Go to the Options tab.
- Click "Advanced" under "Find and replace".
- Click "New rule".
- Copy my description into Name.
- Copy my "Find" and "Replace with" text into their respective boxes. Don't edit this page and copy them directly out of the page source; they won't work. View this page and grab them that way.
- Look at my "Regular expression?" and "Case sensitive?" Y/N boxes, and check the proper options in AWB. If "Case sensitive?" is N/A, it doesn't matter whether the box is checked or not.
- Click OK, and you're good to go.
You could pull these pages up in AWB and make sure that the tests work properly. Let me know if you have any questions or problems.
If you run into any false positives or negatives, please let me know. I'll try to fix them, and then update my regex and unit test to prove that they now handle the new situation. Also, if you dislike any of the changes I'm making, please inform me and we can discuss it. I primarily edit articles about ships, and so I'm not trying to implement these changes everywhere, but if I'm doing something that you think is blatantly wrong we should talk about it.
General
[edit]This section contains regular expressions that make general fixes, not limited to a particular topic or type of unit.
Geographical coordinates
[edit]This section contains regular expressions for converting plain-text geographical coordinates to {{coord}}.
Frequency
[edit]This section contains regular expressions for properly formatting frequency.
Area and volume
[edit]This section contains regular expressions for properly formatting units of area and volume.
Length
[edit]This section contains regular expressions for formatting units of length.
Speed
[edit]This section contains regular expressions for formatting units of speed.
Power
[edit]This section contains regular expressions for formatting units of power.
Torque
[edit]Description | |
---|---|
Fix newton metres | |
Find | |
\bN(?:\s| |-|•)?m\b | |
Replace with | |
N·m | |
Regular expression? | Case sensitive? |
Y | Y |
Text this regex should modify: | Intended result: |
|
|
Description | |
---|---|
Fix foot pounds | |
Find | |
\bft(?:\s| |-|.|·|•|\/)?lbf?s?\b | |
Replace with | |
ft·lbf | |
Regular expression? | Case sensitive? |
Y | Y |
Text this regex should modify: | Intended result: |
|
|
Ships
[edit]Description | |
---|---|
Put non-breaking spaces between "TF" or "TG" (short for Task Force or Task Group) and a number | |
Find | |
T(F|G)\s?(\d) | |
Replace with | |
T$1 $2 | |
Regular expression? | Case sensitive? |
Y | Y |
Text this regex should modify: | Intended result: |
|
|
Description | |
---|---|
Put non-breaking spaces between CruDiv (Cruiser Division) and a number, and capitalize properly | |
Find | |
crudiv(?:\s| )?(\d) | |
Replace with | |
CruDiv $1 | |
Regular expression? | Case sensitive? |
Y | N |
Text this regex should modify: | Intended result: |
|
|
Description | |
---|---|
Put non-breaking spaces between DesDiv (Destroyer Division) and a number, and capitalize properly | |
Find | |
desdiv(?:\s| )?(\d) | |
Replace with | |
DesDiv $1 | |
Regular expression? | Case sensitive? |
Y | N |
Text this regex should modify: | Intended result: |
|
|
Description | |
---|---|
Put non-breaking spaces between DesRon (Destroyer squadRon) and a number, and capitalize properly | |
Find | |
desdiv(?:\s| )?(\d) | |
Replace with | |
DesDiv $1 | |
Regular expression? | Case sensitive? |
Y | N |
Text this regex should modify: | Intended result: |
|
|
Temperature
[edit]Description | Find | Replace with | RegEx? | Case sensitive? |
Tests | Intended result |
---|---|---|---|---|---|---|
Replace "centigrade" with "Celsius" | centigrade | Celsius | N | N |
|
|
Get "Celsius" capitalized properly | celsius | Celsius | N | N |
|
|
Get "Fahrenheit" capitalized properly | fahrenheit | Fahrenheit | N | N |
|
|
Remove spaces from between degree symbol and C or F | °(?:\s| )([CF]) | °$1 | Y | N |
|
|
Replace °Celsius with °C | °celsius | °C | N | N |
|
|
Replace °Farenheit with °F | °fahrenheit | °F | N | N |
|
|
Put a non-breaking space between the temperature and °C or °F | (\d)\s?(°[CF]) | $1 $2 | Y | N |
|
|
Get rid of degree symbol in temperatures in Kelvin | (\d)(?:\s| )?°K | $1 K | Y | N |
|
|
Final
[edit]These are general-purpose regexes, but they should be run last, because their purpose is to make some final fixes after all the other work has been done.
Description | |
---|---|
Use non-breaking spaces between numbers and abbreviated SI units, per MoS. This does not try to understand and fix improper SI units, so it needs to be run at the end, after all of that stuff has already been taken care of. | |
Find | |
\b(\d+)(?:\s|-)?[ ]*(Y|Z|E|P|T|G|M|k|h|da|d|c|m|µ|n|p|f|a|z|y)?(m|g|s|A|K|mol|cd|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|lm|lx|Bq|Gy|Sv|kat|M)(²|³)?\b | |
Replace with | |
$1 $2$3$4 | |
Regular expression? | Case sensitive? |
Y | Y |
Text this regex should modify: | Intended result: |
|
|