FFT of square wave: maths and actual numbers do not coincide
The continuous-time Fourier transform of a single rectangular pulse $p(t)$ of duration $[-d,d]$ is :

$$ P(\Omega) = \frac{ 2 \sin(\Omega d) }{\Omega } = 2 d \cdot \text{sinc}( \frac{\Omega d}{\pi} ) \tag{1} $$

where $\Omega$ is the frequency in radians per second.

You can not represent $p(t)$ or $P(\Omega)$ using a sampled-data computer system because $p(t)$ is not bandlimited. However, there is an analogous definition of a rectangular pulse in discrete-time, defined as a sequence $x[n]$ of duration $[-d,d]$, with $d$ being integer, whose discrete-time Fourier transform is :

$$X(e^{j\omega}) = \frac{ \sin( \omega (2d+1) /2 ) }{ \sin( \omega /2 )} \tag{2}  $$

which is called a periodic-sinc or a Dirichlet kernel. Note that this is not a simulation of the continuous case.

Using the computer with N-point DFT/FFT, implementation of discrete-time case will be

$$X[k] = X(e^{j\omega})|_{w_k = \frac{2\pi}{N}k} = \frac{ \sin( \frac{\pi k}{N} (2d+1)) }{ \sin( \frac{\pi k}{N} )} \tag{3}  $$

A Matlab/Octave implementation is as follows

d = 3;       % rectangular pulse in [-d,d]
N = 32;      % DFT/FFT length

k = 0:N-1;   % DFT index

X = sin( (pi/N)*(2*d+1)*k)./sin( (pi/N)*k));
X(1) = 2*d+1;

x = real(ifft(X,N));   % compute inverse DFT on Xk

figure,stem(k,xp);
title('rect-pulse from inverse DFT of periodic-sinc');


Note that the circularity of DFT implies that negative indices of the pulse $x[n]$ are at the right edge.